Last Updated: February 25, 2016
·
2.799K
· tilsammans

Install Ruby from source on Ubuntu

I like to install Ruby from source. I find that using RVM or rbenv adds a level of indirection I'm not comfortable with on the server. To build it, this protip lists the absolute minimum packages required. Without these, you cannot use Ruby.

First we are going to need a few essential packages:

$ sudo apt-get install build-essential openssl-dev zlib1g-dev

Followed by a straightforward install from source. I am installing 2.0.0-p0 but a newer version is fine too.

$ wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
$ tar xvfz ruby-2.0.0-p0
$ cd ruby-2.0.0-p0
$ ./configure && make && sudo make install

Rails

Now you're all set, but you probably want to install Rails too. I am going to use Passenger here, since it almost always just works and is by far the least amount of hassle. I recommend you start using Passenger and only switch to something like Thin/Unicorn if you hit a wall. Don't believe intarweb rumors about all kinds of problems. This combination works like a tank in production.

For Ruby 2 you will need passenger version 4.0.0.rc6 or later.

$ sudo apt-get install nodejs libcurl4-openssl-dev
$ sudo gem install bundler
$ sudo gem install passenger --version 4.0.0.rc6

I do recommend using nginx as a web server. You are going to want to take a look at https://gist.github.com/mikhailov/3052776 with a ton of performance tweaks. But for now just run the stock passenger nginx installer:

$ sudo passenger-install-nginx-module --extra-configure-flags="--with-ipv6"