Linux‎ > ‎Ruby & Rails‎ > ‎

Install Ruby using ASDF

posted Dec 29, 2013, 7:48 PM by Chris Martin   [ updated Jul 21, 2022, 6:00 AM ]
Don't install the ruby packages supplied with your linux distro.  they are usually out of date
Instead, install via the RVM (Ruby Version manager). This will also allow you to install different versions and configurations for different projects.   The beautiful part of this is that it installs RVM and Ruby to our home directory, providing a sandboxed environment just for us.  

First update the app repository and install some prerequisites.
$ sudo apt-get update
$ sudo apt-get install build-essential openssl libreadline8 libreadline-dev curl git zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libncurses-dev automake libtool bison subversion pkg-config curl gawk dirmngr gpg 

Now install ASDF
$ cd ~/
$ git clone ~/.asdf --branch v0.10.2 # This installs ASDF via git

Edit the shell enviroments for next login
Add the following to ~/.bashrc:
. $HOME/.asdf/                # load the functions
. $HOME/.asdf/completions/asdf.bash  # load command compleations

reload our shell environment
$ . ~/.bashrc

Now that ASDF is installed we can Install Ruby
$ asdf plugin add ruby
$ asdf install ruby <version>

Now tell rvm that we want to use this version 
$ asdf local ruby <version>

Now that we have installed ASDF and a version of Ruby, we can install Rails. Because RVM is installed to our home directory, we don't need to use sudo to install things.  This will install the rails gem and the multitude of gems that it and its dependencies depend on, including Bundler.
$ gem install rails -v <version>

Install the Postgresql gem:
first make sure that postgresql is installed
$ sudo apt-get install postgresql

install the gem:  note the dependency on libpq-dev (for Ubuntu)
$ sudo apt-get install libpq-dev
$ gem install pg

Get a copy of the database and install it in to your own local database (see the posting on postgress backup and restore)

Next you can checkout the source using git (the separate post on setting up git).

To get all the gems loaded in your project change to the root directory of the application and run
bundle install

To run the application in a web server use
rails server