Installing Ruby using Rbenv on Ubuntu 17.10

This post details every step taken to install Ruby (and Rails) on Ubuntu 17.10

Installing Ruby using Rbenv on Ubuntu 17.10

Below is every step I took to get Ruby (and Ruby on rails) installed on a vanilla install of Ubuntu 17.10.

First download and install rbenv and rbenv-build and get them set up in your bash profile.

$ sudo apt-get install git
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
$ cd ~/.rbenv && src/configure && make -C src
$ cd ..
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ source ~/.bashrc

NOTE: If you are using Debian instead of Ubuntu then it would be .bash_profile instead of .bashrc

Next we install the remaining requirements for Ruby.

$ sudo apt-get install build-essential
$ sudo apt-get install -y libssl-dev libreadline-dev zlib1g-dev
$ rbenv install 2.4.3
$ rbenv global 2.4.3
$ ruby -v
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]

NOTE: instead of global you could use local instead.

Then you can check everything is installed OK using the rbenv-doctor script.

$ sudo apt install curl
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /home/dean/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /home/dean/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20171226-3-g01e7b7b)
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK

Now update gems and install bundler.

$ gem update
$ gem install bundler

If you are planning on doing some web development and want to install rails, then we need to install a few dependencies first.

$ sudo apt-get install sqlite3 libsqlite3-dev
$ gem install rails -v 5.1.4
$ mkdir rails_projects
$ cd rails_projects
$ rails _5.1.4_ new hello_app

In order to actually run the rails server for a project that has the uglifier gem installed then we also need to install a JavaScript runtime such as nodejs

$ sudo apt-get install nodejs
$ rails server
=> Booting Puma
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.3-p205), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop