Wednesday, March 28, 2012

Installing RVM on Ubuntu 11.10

RVM is an amazing tool. It's a tool that enables mixed you to switch between different version of Ruby with a simple command line entry.

Setting it up posed a few challenges for Ubuntu Server 11.10. I've installed it a few times in the past, but I'd always installed it in "single user mode". Meaning, I only installed it for my login which gave me the ability to install things in my own sandbox without requiring elevated privileges. However, for my web server I wanted to set up RVM for all users. This way my Git user can specify Ruby versions on demand just the same.

To do this, I followed the steps on their website, but I couldn't get my "rvm install x.x.x" commands to work. When I typed the following command:

rvm install 1.9.2

I got a slew of errors. This was never a problem for me in 'Single User' install mode, so I wasn't sure what the problem could be. I didn't do my reading and ended up trying all kinds of things. I checked the requirements, installed all kinds of additional packages, even updated / upgraded my entire environment using:

sudo apt-get update

as well as

sudo apt-get upgrade

I waited and waited while it updated my system. When I tried entering the rvm install command again, it still generated the same set of errors. As it turns out, I simply had to append rvmsudo at the front of this command, like so:

rvmsudo rvm install 1.9.2

This preserves the RVM environment and passes it onto sudo.  Once I did that, things started working. :) Moral of the story: RTFM!

Oh and you should note that this doesn't set v1.9.2 as your current Ruby version yet; it merely installs it. To begin using it, type the following command:

rvm use 1.9.2

Hope this helps somebody.

Tuesday, March 27, 2012

Git Bash

Since I've been using Linux, I find it painful to use the old cmd shell in Windows anymore. I've been using Windows for years, but never really got excited about the command line. When I made the switch to Unix, the command line became fun for me. I had full blown access to my computer using nothing but my keyboard. More impressively, I had full blown access to other (*nix) computers using nothing but my keyboard as well... all within the same terminal shell.

To me, it feels as though Unix made the command line it's foremost tool. Anything and everything can be done from the command line. In many cases, I've heard that many of the Unix applications actually interface with the kernel using command line calls to the various shell apps. Whereas, I feel that Microsoft really focused on giving most of it's power through various forms and dialogs. Most anything can be done inside the cmd prompt, I'm sure, but most of the functionality is taught and shared through the various user interface applications. Don't get me wrong!! There is great power there and it's very useful for most people! Hell, it's what I got started on; I respect my roots. :)

I never really appreciated the command line until I got my Mac. My buddy, Ben, showed me how much power Mac's have using nothing more than All the sudden it became fun for me. I could open my Terminal app and punch in basic commands to make my computer do things. It was like programming my computer without using an IDE. It was very different from anything I was used to in Windows. Once the commands became natural to me, I began plugging them together using pipelines and so forth. At some point it all clicked and I realized how powerful the command line really was. The more I used it, the more I found myself customizing it to fit my needs. I could change colors, change my prompt, change the way I edited the command line, and so forth. I have all kinds of aliases defined that do some pretty sophisticated stuff with a few keystrokes.

What are my options for command line goodness on Windows though?

PuTTY is an old school terminal emulator for Windows. This tool is used more for logging into other computers though. It's not really intended for managing your local client machine. I'm sure there are ways to make it work this way, but it's not a good replacement for cmd in my opinion. This applications is how I was first introduced to Linux and SSH; it gave me a bad taste for Linux right away.

Console is a replacement for cmd, and I've not yet downloaded it. It sounds to me like it is more of a shell consolidator. Basically, it allows you to choose any shell that you want using a tabbed interface. So in "programming terms" it's more of a composite shell. :) This doesn't give me my Unix tool set though with all the customizations that I'm used to in Unix though... Again, I need to look into this more, but it's what I've gathered from my (minimal) research.

Cygwin is a set of tools that sit inside of the Windows cmd terminal (if I understand correctly). It allows you to manage your computer using all the same application names (ls, pwd, cd, etc..) but this isn't really a full blown replacement for bash; rather a set of tools that mask the cmd terminal with Unix like tools IMO. I'd much rather have a full blown version of the Bourne Again SHell sitting inside Windows 7 instead.

Along comes Git Bash for Windows.

When I installed msysgit, (the Git binaries for Windows), it came with a "Git Bash" shell. At first I thought it was another version for the PuTTY terminal emulator. However, the more I use it the more I realized that it's the real deal. It is (almost) exactly like having a Unix Bash Shell inside Windows finally. I use it for everything now. I open it up when I sit down to work and it stays open until I close my laptop. Best yet, I can secure shell into my *nix VM's and manage them remotely from Windows now. I no longer have to open up PuTTY to login to my VM's. I can grep, find, pipe, less, generate ssh keys, you name it. I can even customize the shell with a .bashrc file. For example, my command line editor is configured to use vim keybindings (ie. set -o vi)... IN WINDOWS!! It's great!

The one thing I can't do with this shell is sudo commands with administrative privileged. However, that's more of a Windows vs. Linux thing, rather than a bash shell feature. To get around this, I simply have to open another Bash shell "As Administrator" and perform my operations inside that shell. I don't mind this trade off.

By far, my favorite feature of having a bash shell in Windows is that I have full vi (pronounced "vee eye") editing capabilities on any text file. I'm finding it harder and harder to live without this single feature.

There you have it... Check it out. Git Bash for Windows is the cats pajamas.

Sunday, March 25, 2012

Hosting My Own Websites From Home

Last December, I purchased a handful of servers, along with some switches and a 7 ft tall rack to house them all off of a buddy. A month later, I got them setup at another buddies office, but after a few delays and realizations, I decided to bring them back home and set them up in my own house.

Doing this presented some challenges in regards to everything that comes with hosting your own servers in your own house. For example, the servers require a dedicated 220 service. Not only that, but I needed to put the servers in a place where they will stay dry and cool. Oh did I mention, the servers are loud as hell? Like "jet engine" loud... Lastly, in order for them to be useful, I needed to have my own dedicated static IP address running to the house. This one was the big one; it required that I switch from one ISP to another! With this change came a new TV service and everything. Yes, I'm committed to my goal of hosting my own sites. :)

Another big obstacle that I have yet to hurdle is that there is (currently) no place in our house that is ideal for setting these servers up that is dry / cool / sound proof. Given all of these factors, I've decided to shelve them for a few months and figure out a plan this summer to get a sound-proof room built with it's own thermostat in the garage with it's own 220 service (more on that in a later post).

In the meantime, I've configured my old development machine to be my web full time webserver; it's working great so far. The server is an old 4gb RAM / 64bit AMD box with a 160gb HD. I've wiped it clean and installed Ubuntu Server on it with OpenSSH and a simple LAMP configuration. I installed Git and configured Gitosis so that I can easily manage new code repositories from anywhere without ever logging in and configuring users and directories. The site is currently only hosting one Ruby on Rails site so far (which isn't online yet). Once I get everything ticking like clock work, I will host a slew of websites. Some for friends and family, but some for profit of course.

Everything has been pretty strait forward so far. The hardest part for me has been configuring the static IP. In the last 12 hours, I've spent 8 (solid) hours trying to get my network configured correctly. I've been through books, websites, Unix man pages, and a few shot-in-the-dark attempts. All that, and I'm still not online with it. It's amazing that I've made it as far as I have in the computer industry without fully understanding NAT, DHCP, DNS, and "Port Forwarding". I've learned more about these terms in one day than I have in the last 12 years, I still have quite a bit to learn too...

For now, Jennifer is just happy to have her internet back up. :) Tomorrow, I plan to call my ISP and have them walk me though it once and for all.