paint-brush
Bare Metal Rubyby@dreikanter
662 reads
662 reads

Bare Metal Ruby

by Alex MusayevJune 30th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The goal was to find a fast and reliable approach for provisioning expendable virtual machines for Ruby development environment. This manual explains how to install the most recent stable version of Ruby on Linux, without using rbenv or alternative version managers. It is required to build native extensions for Ruby gems, and only one version is required system-wide. The same operation could be done manually with the same operation as setting the target directory to the user home, and these lines to your bashrc are needed.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Bare Metal Ruby
Alex Musayev HackerNoon profile picture

This manual explains how to install most recent stable version of Ruby on Linux, without using rbenv or alternative version managers. The goal was to find a fast and reliable approach for provisioning expendable virtual machines for Rails development environment.

Basic assumptions:

  1. Installation speed matters (don’t wait while Ruby is building).
  2. Only one version of Ruby is required system-wide.
  3. We’re using Ubuntu.

Step 1. Install prebuilt Ruby from Brightbox

Notice dev package that should be installed in addition to the primary one. It is required to build native extensions for Ruby gems.




sudo apt-get install software-properties-commonsudo apt-add-repository ppa:brightbox/ruby-ngsudo apt-get updatesudo apt-get install ruby2.4 ruby2.4-dev

Brightbox manual propose a tool called ruby-switch that can help switching between multiple Rubies on the same system. Since there will be only one of them, this step is unnecessary.

Step 2. Make gem work without sudo

By default gem will try to install new gems to the system folder (e.g. /var/lib/gems/2.4.0), which is no good. Ruby version managers override this path with something under user home directory. But the same operation could be done manually. To permanently set target directory to user home, and these lines to your ~/.bashrc:


export GEM_HOME=$HOME/.gem/ruby/2.4.0export PATH=$HOME/.gem/ruby/2.4.0/bin:$PATH

Here is the most important thing you need to know about Ruby version managers to understand what exactly they do in system configuration:

RubyGems’ default local repository can be overridden with the GEM_PATH and GEM_HOME environment variables. GEM_HOME sets the default repository to install into. GEM_PATH allows multiple local repositories to be searched for gems. (http://guides.rubygems.org/command-reference/)

Step 3. Run a quick ad-hoc test

Log into shell, and execute these commands to ensure gem and ruby binaries are available, gem home path is configured correctly, and native extensions could be built:



cdgem install bundler railsrails new testapp

Or just execute gem env to see the paths without installing anything.

Here is a full Vagrantfile to provision new Linux VM with Ruby, following the described approach: https://github.com/dreikanter/vagrant-rails 🍰

Peace.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMIfamily. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.

To learn more, read our about page, like/message us on Facebook, or simply, tweet/DM @HackerNoon.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!