A few days ago I threw together a new website for myself, built in ruby and styled with Sass. I’m also about to embark on a new project to rebuild an existing PHP-driven API in ruby, primarily as a demonstration of how quickly it’s possible to make things using ruby, and because API design is fascinating me at the moment.
Before embarking on these projects, I decided that I wanted to sort a few things out:
- A decent local ruby environment that I actually understand.
- An easy way to do things like compile assets and refresh my browser when developing locally.
- A decent build process for the API project.
I’ve got a copule of articles in the works covering the latter two points but for now, I’d like to talk about the first one.
RVM pisses me off
To be fair, RVM was a lifesaver when I first installed it. Before that, I had no way of managing different ruby versions or the gems that went with them and spent far too much of my time trying to work out why some old project wouldn’t run. My system was littered with old gem versions (including Rails 0.9!) and it wasn’t pleasant. Along came RVM to the rescue – with gemsets so I could manage things on a per-project basis. Great.
Them problem was, I had no idea where any of those gems were kept, or where the ruby versions were, or what RVM had done to my shell (not to mention
rvm gemset use email@example.com). I probably should have paid more attention when I installed it all.
With the advent of Bundler, my headaches regarding gem management were reduced somewhat, but what if I ran
bundle install in the wrong gemset?
rbenv is much cooler
Mostly because I get it. Coupled with bundler, it allows me to pretty much ignore my ruby version and gem management and feel confident that when I
cd into a project’s folder, all I have to do is
bundle install and get on with my work. I also freed up a considerable amount of space on my hard drive by binning millions of gems.
I toyed with writing in great detail about the installation process for rbenv (and how to get rid of RVM), but plenty of other people have written about that. Instead, I thought I’d share the steps I took to get it all sorted. This isn’t so much of a ‘howto’, as a dump of my bash history.
Disclaimer Thing: I ran into a few issues, and spent quite a bit of time googling - the following process is the result of that googling and I’m afraid I can’t remember all (read: any) of my sources. I may also have forgotten some stuff I did, so don’t come after me with a pitchfork if it doesn’t work.
Stuff I did to switch from RVM to rbenv
Kill off RVM:
rvm implode gem uninstall rvm sudo rm -rdf /etc/rvmrc rm -rdf ~/.rvmrc sudo rm -rds ~/.rvm sudo rm -rdf /etc/profile.d/rvm
Remove the RVM wrappers from
sudo rm -f /usr/local/bin/erb sudo rm -f /usr/local/bin/gem sudo rm -f /usr/local/bin/irb sudo rm -f /usr/local/bin/rake sudo rm -f /usr/local/bin/rdoc sudo rm -f /usr/local/bin/ri sudo rm -f /usr/local/bin/ruby sudo rm -f /usr/local/bin/testrb
Get rid of any references to RVM in your
.bash_profile. This obviously depends how you set it up. I restarted my machine here, just to make sure I had a clean slate – that’s probably not needed, though.
Install Homebrew and then install rbenv (I already had homebrew installed):
brew update brew upgrade `brew outdated` brew install rbenv brew install ruby-build
If you’ve already got homebrew installed, check that you have
brew --repository/Library/Contributions/brew_bash_completion.sh in your
Get rid of the default gems from before you were using RVM (I also updated the system gems just so I had a ‘clean’ system installation of ruby – not that I’ll ever use it):
which ruby ruby -v gem list for i in `gem list --no-versions`; do sudo gem uninstall -aIx $i; done gem update --system
Double-check for old versions, just in case:
/usr/bin/gem list --no-versions
Install ruby using rbenv and set 2.0.0 as the global default:
rbenv install 1.9.3-p448 rbenv install 2.0.0-p247 rbenv global 2.0.0-p247
Install any global gems – there is some stuff I don’t want to manage in bundles:
ruby --version gem install bundler hirb json rake rdoc rerun sass shotgun guard guard-shotgun thor wirble showterm http pry bundler rbenv rehash gem list
git clone -- git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler
Install the heroku toolbelt and login:
The last thing I did was
cd into a project using 1.9.3 and check everything was working, then rebuild the system locate database:
cd /old-project ruby -v #=> 2.0.0-p247 rbenv local 1.9.3-p448 ruby -v #=> 1.9.3-p448 bundle install # Does it work? cd .. ruby -v #=> 2.0.0-p247 sudo /usr/libexec/locate.updatedb # Update locate database
Like I said, this isn’t meant to be a complete walkthrough, I just hope that some of the bits here will be useful to anyone else doing the same thing.