Thursday, February 21, 2013

Ruby RVM redux (RVM on Windows too!)

Installing Ruby using RVM 

Using Wayne Seguin’s RVM (Ruby Version Manager) is definitely the best way to go for installing Ruby on most UNIX platforms. It allows any kind of Ruby to be installed, even multiple versions, and will keep everything in the home directory under .RVM, so no admin-level system installations are required. It is very well maintained, and considered the defacto standard for maintaining and updating Ruby installations. Visit http://rvm.io for more information. After installation, use: rvm notes for up-to-date information about the installed framework.

 UNIX Installation 

These instructions should help you get RVM and Ruby MRI installed. During this process, you must be connected to the network the whole time. RVM will download things during the build.

First, install the bash shell. Bash is the required login shell for the account in which RVM is installed. RVM installs itself as a Bash function. For X-Windows: Make sure your terminal is set to call a login shell with

bash --login 

Next, install the package: curl

Do this as  root using your OS package manager. The specifics will depend on your system.

NOTE: Do not run the rest of these commands as root. RVM requires they be run with the same privileges as the account you’re logged into.

$ \curl -L https://get.rvm.io | bash -s stable 
(Include the forward slash at the beginning of the command line.)
This installs the RVM framework


$ rvm list known 


The above command list all the possible rubies that can be installed. We will use MRI version 1.9.3 in this example, but the latest one should be used. That’s the one under the MRI section listed just before -head. The current minor version is p385.

$ rvm requirements

The above command lists all dependencies and tasks needed to build and install Ruby. Execute all instructions given. These are required software installations. Failure is likely to occur with the build or runtime if the steps are not taken. RVM will tell you what you need to do to prepare your system, and hand you the command lines to do it.

$ rvm install 1.9.3 

The above command compiles Ruby 1.9.3

$ rvm use 1.9.3 --default 

The above command sets the built ruby as current and default version.

$ rvm info 

The command above verifies the Ruby installation.

$ ruby --version 

Now all that's left is to verify IRB behaves properly:

$ irb  


Windows installation (cygwin) 

Goto http://www.cygwin.com and download setup.exe from the link on that page. Save the program to your desktop. It is your only package manager. The direct URL is http://cygwin.com/setup.exe

Double-click setup.exe and follow the wizard steps to the package manager screen. That’s the one with all the software categories in a tree. Use the search box to locate and install the following packages and all their dependencies:

curl (net/curl) 
libcurl-devel (net/libcurl-devel) 
cert (net/ca-certificates) 

Open the cygwin bash shell from the desktop icon or start menu. Install RVM from inside the shell:

$ \curl -L https://get.rvm.io | bash -s stable 

Exit the shell and re-open it.

Run:

$ rvm requirements

The above command lists all dependencies and tasks needed to build and run Ruby. This is a must-do step. But since the cygwin third-party packages change so much in their availability, you may have to fudge a bit in installing some things listed.

For example, rvm requirements lists the build-essential package to be installed. That is a meta-port of a bunch of build tools. At the time of writing and testing this, the build-essential package was available in the cygwin package manager. An hour later it disappeared without a trace.

Since this ingredient is so important, I’ve listed the tools below that I think were in the meta-port.. When possible, choose -devel versions of the software, and select the mingw ports if available.

Here is a mostly-correct list of packages to select and install:

mingw-gcc-g++ 
make 
mingw-zlib1 
libyaml-devel 
libsqlite-3-devel 
sqlite3 
libxml2-devel 
libxslt-devel 
autoconf (highest version) 
libgdbm-devel 
ncurses-devel 
automake (latest) 
libtool 
bison 
pkg-config
readline: GNU readline

Now compile Ruby 1.9.3:

$ rvm install 1.9.3 

And now set the built ruby as current and default version:

$ rvm use 1.9.3 --default 

Verify the Ruby installation:

$ rvm info 
$ ruby --version 

Lastly, verify irb does not crash

$ irb

Wednesday, February 20, 2013

Virtual machines and Service Jails

If you are really serious about getting the most out of your hardware, you'll certainly consider using virtual machines. Two, three or even 80 virtual operating systems per physical server is a hard deal to turn down, whether you are an IT shop or a lone developer. It is pretty much something for nothing. 

There are various flavors of technologies out there to virtualize a computing environment. They generally range from heavyweight virtualization solutions (such as VmWare and Virtualbox) which emulate everything in software found in hardware on the machine from the BIOS and devices to the disk; to lightweight virtualization which can be found in certain domains like Apache web server virtual hosts, where a chroot directory and domain routing may the only thing differentiating web hosts.

Heavyweight virtualization tends to be better suited for the desktop, in situations where you'd like to run one OS inside another. Lightweight virtualization tends to be better for servers, because it goes easier on resources and is more abstract, often with no GUI to manage things. For example, VMware will emulate a single BIOS, kernel, drivers and OS per virtual machine. It offers a more comprehensive container, but uses much of the host machine's resources. On the other side of the spectrum, an Apache virtual web host on a server farm will offer customers a complete web publishing domain, but hundreds of virtual hosts can occupy a single physical server.

In the mid-range of all this, are paravirtualization technologies like Xen and FreeBSD jails. Paravirtualization, although not terribly distinct from other forms of virtualization, is where the vitual mechanism is bound closely to the operating system that hosts it. The host is aware of the virtualization technology being used, and shares its own resources with it, such as a kernel. This is generally more efficient if you want to run a bunch of virtual machines of the same OS type within a host, rather than emulate some other operating system on your desktop. 

There are other advantages to the middle-weight paravirutalization approach besides running more VMs per physical machine. Maintenance and upgrades to many VMs can be sourced from a single location on the host. Security and integration is  better understood by the host's development team. Management tools are usually available that enable you to easily monitor, create and destroy VMs. 

Furthermore, the ability to divide VMs by service (database server, login host, development environment, testing environment, web server, build server, source control server) allows a full organizational development and deployment environment to be emulated on a single piece of even-not-so-good hardware. Ideal for a home network with a for a single professional user. Technologies and services found only on large scale systems can be emulated on a single machine that has been subdivided into many discrete machines. 

On FreeBSD, the service jail is the approach to use, and probably the best-integrated and most efficient of all the technologies. Typically,  Xen systems are best used one-per-core on Linux systems - they are a more heavyweight solution than FreeBSD service jails, which can be ganged-up to 50+ machines on a dual-core system and still have good performance.

The requirement, of course, is that you run FreeBSD. This is not so bad. It's pretty much the OS of choice for commercial server farms even without the jails, since it can easily be built from source, the licensing doesn't require you to divulge your source code, and it's completely not owned or controlled by any corporation - much like Linux. But unlike Linux, it's maintained and developed in a more selective, controlled and organized environment. The code base is cleaner, and the engineering standards are higher. Definitely the platform of choice, and still a best-kept-secret among technical people.