As mentioned in my last post, I recently switched to Jekyll after briefly flirting wih Toto. I hadn't used ruby much before, much less deployed it, so it was a bit of a hassle to set up a ruby environment on my Ubuntu linode.
When I've have to dabble with ruby in the past, I got generally got away with using RVM. However, I didn't want to use a system-wide rvm install because I was afraid that its path management could clobber and conflict with others systems like virtualenv for Python. In retrospect, I don't think that's true, but rvm does warn you about clobbering paths and I guess I overreacted.
Instead of compiling ruby myself from scratch, I tried to do things the Debian/Ubuntu way with apt.
Before I go any further, let me put emphasis on the fact that I tried to do things the Debian/Ubuntu way. It's not perfect by any means. Would I call it the right way? No, not really. But it works well enough.
I still think RVM is still the best way to install ruby. Look here for a pretty good guide on setting up RVM with Ubuntu 10.10. But, you'll see that he explicitly mentions adding rvm to root. I didn't want to do that, but still needed root to have access to ruby and the gem binaries for thin, which I used with Toto. That's why I went down the following path.
Installing ruby 1.9 with apt requires the following command
sudo aptitude install ruby1.9.2 ruby1.9.1-full build-essential
You may notice that I use aptitude instead of apt-get. That's just personal preference at this point. If you prefer apt-get or don't have aptitude, you can just use apt-get.
In order to keep the 1.9.x packages from conflicting with ruby1.8 ones, the binaries all have 1.9.1 appended to them. For example, ruby is installed as /usr/bin/ruby1.9.1 instead of /usr/bin/ruby. I wouldn't be surprised if some sort of update-alternatives magic could be used to correct this, but I used a quick and dirty aliasing trick instead.
cd /usr/local/bin
sudo su
for f in /usr/bin/*1.9.1
do
filename=$(basename $f);
newname=${filename%1\.9\.1};
ln -s $f $newname;
done
exit
I'm not a bash guru, but the code works well enough so I figured I should share. It creates a handful of soft links in /usr/local/bin, which adds them to the path but is outside the scope of Debian packaging. The first line changes directory and the second switches the current user to root. This lets us write in /usr/local/bin. The bash loop walks over all files in /usr/bin and looks for ones that end with 1.9.1. It then strips the 1.9.1 from the name and creates the soft link in /usr/local/bin. The final exit then returns back the regular user.
After this, do a quick ruby -v to make sure the alias is working.
The next step was installing the gems I need. In this case, jekyll and jekyll_ext. Since I opted for ruby 1.9.x, RubyGems is actually part of Ruby and doesn't need to to be installed on its own. One less package to bother with. However, gems don't play very nicely with the Debian way of things because they aren't controlled by apt/dpkg. So we'll need more soft-linking shenanigans
sudo gem install jekyll jekyll_ext
cd /usr/local/bin
sudo su
for f in /var/lib/gems/1.9.1/bin/*
do
filename=$(basename $f);
if [ -e $filename ]
then echo "$filename already exits";
else sudo ln -s $f $filename;
fi
done
exit
Install the gems first, then move to /usr/local/bin and soft link away just like before, adding all the binaries from the default Debian gems location (stuff like jekyll and rake). This time I added a file existence check, though that technically isn't necessary. ln can't create a soft link if another file already exists with that name.
Jekyll supports pygments syntax highlighting out of the box, so I also installed that as well
sudo aptitude install python-pygments
Now that all the binaries for ruby and the gems are in my path, I can do all the "regular" deploy stuff with ease. With Toto, I had to set up thin and add a config, but Jekyll just gives me static files. In fact, I really could have generated the site on my laptop and just pushed the files up to the linode, avoiding this entire process. However, since I had the infrastructure in place, I decided to set up my site so it runs jekyll and redeploys every time I push to my git repository.