DEV Community

Cover image for A naive installation of Ruby and Rails on OpenBSD
olistik
olistik

Posted on

A naive installation of Ruby and Rails on OpenBSD

image credits

Here's the environment we'll play with (just an excuse to use neofetch):

OpenBSD environment information as shown by the command  raw `neofetch` endraw

The packages are handy but I'd prefer to keep the installation within my home in order to make actions like bundle install work without the need for super user permissions or custom configurations.

Also, I don't mind reducing the number of indirection layers.

First of all prepare the directory in which we'll install Ruby.

$ mkdir ~/.rubies
Enter fullscreen mode Exit fullscreen mode

Note that we're doing this to avoid the need for the superuser.

Then download the sources of the latest version (3.0.2) and install them into our user directory:

$ curl -LO https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.2.tar.gz
$ tar xvfz ruby-3.0.2.tar.gz
$ cd ruby-3.0.2
$ ./configure --prefix ~/.rubies/3.0.2
$ make
$ make install
Enter fullscreen mode Exit fullscreen mode

For convenience, link the newly installed version with the "current" alias:

$ ln -s $HOME/.rubies/3.0.2 $HOME/rubies/current
Enter fullscreen mode Exit fullscreen mode

Edit ~/.profile and add $HOME/.rubies/current/bin to the $PATH so that the binaries will more easily be available in the terminal:

PATH=$HOME/.rubies/current/bin:$HOME/bin:__the rest of the path list here__
Enter fullscreen mode Exit fullscreen mode

Here's our little precious:

$ ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-openbsd6.9]
Enter fullscreen mode Exit fullscreen mode

Nokogiri

Using the same approach described for FreeBSD in https://nokogiri.org/tutorials/installing_nokogiri.html#installing-using-standard-system-libraries we'll install the pkgconf package (note that the current user needs to be enabled for doas):

$ doas pkg install pkgconf
$ gem install nokogiri --platform=ruby -- --use-system-libraries
Enter fullscreen mode Exit fullscreen mode

A new dawn

Time to test that the big boy works (picking "rails API only" to make things simpler):

$ gem install rails
$ rails new --api yolo
$ cd yolo
$ rails server
Enter fullscreen mode Exit fullscreen mode

Now open another terminal (or the browser at http://localhost:3000) and enjoy the view:

$ curl http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

Two woman jumping happily on the street

image credits

Latest comments (1)

Collapse
 
cosmouser profile image
Alexander Martinez

Thanks for this! Overall it is very helpful. There were some typos in the section about linking to current. Walking through the steps, I needed to install libxml and libxslt in order to install nokogiri.