Ruby 3.0 Installation On OpenBSD
Table of Contents
Overview
This post goes through installing Ruby 3.0 on OpenBSD 7.0-current. This is here for reference so it’s easier in the future. Should there be changes to the ruby30 package, I will create another post for it.
Note that when you install packages, you will need to do so with elevated privileges. You can utilize doas(1); assuming you have it configured, or you can use su(1) and type in your root password to do so.
Also note that we’re talking about a project that’s frequently developed. The method for installation could change at any time. Should this need to be updated, there will be a post with the new method that works.
As always, if I find any errors or if I am informed of errors, I will fix them.
Installing ruby30
To install Ruby on OpenBSD, you need to
First, need to make sure packages are up to date.
pkg_add -u
Second, install the ruby package. This can be done in multiple ways.
Currently, there are versions of Ruby. These include ruby-2.7.5p0
and ruby-3.0.3p0
which can beinstalled by replacing ruby%3.0
with ruby
in the following command. I bypass the ambiguities behavior
using the first method. Otherwise, I would have to choose option 2.
All of this information regarding this behavior in pkg_add(1) can be found in its man page.
Below is the commnd I use to install ruby30.
pkg_add ruby%3.0
When ruby is finished installing, there are some things needed before it
works properly. If ruby30 is the desired version of Ruby, symbolic links
will need to be created so; for example, ruby
opposed to ruby30
.
This is more so for new users that may not know. OpenBSD does a pretty good
job at providing needed configuration in the output after the install.
The following commands are provided when the installation process is completed. As explained above, these commands create a symbolic link for the ruby30 executable. To do this, use the ln(1) command.
Note the commands need to ran as an elevated user.
ln -sf /usr/local/bin/ruby30 /usr/local/bin/ruby
ln -sf /usr/local/bin/erb30 /usr/local/bin/erb
ln -sf /usr/local/bin/irb30 /usr/local/bin/irb
ln -sf /usr/local/bin/rdoc30 /usr/local/bin/racc
ln -sf /usr/local/bin/rdoc30 /usr/local/bin/rdoc
ln -sf /usr/local/bin/rdoc30 /usr/local/bin/rbs
ln -sf /usr/local/bin/ri30 /usr/local/bin/ri
ln -sf /usr/local/bin/rake30 /usr/local/bin/rake
ln -sf /usr/local/bin/gem30 /usr/local/bin/gem
ln -sf /usr/local/bin/bundle30 /usr/local/bin/bundle
ln -sf /usr/local/bin/bundler30 /usr/local/bin/bundler
ln -sf /usr/local/bin/typeprof30 /usr/local/bin/typeprof
When that’s done, add the .gem
directory located in the users $HOME
directory to their PATH. If they’ll need to program or run Ruby applications
on the machine it’s being run on. This is the short and sweet version so Ruby
gems can be installed in the current users home directory.
I recommend that if users need to use Ruby regularly, that this addition to
the PATH is added to the rc file for the shell they use. I currently use
zsh(1). So, I added this to my .zshrc
file.
export PATH=$HOME/.gem/ruby/3.0/bin:$PATH
Now finally, installation for Ruby 3.0 is complete. The version of Ruby has been provided below to show that it’s installed.
ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-openbsd]
One thing I would like to mention that if gems are installed for users, there may be some configuration required for those gems. Symbolic links may need to be created for the gem. This is generally dependant on how many flavors the gem has. It’s simple. Create the symbolic link and make sure the symbolic link doesn’t have the gem version appended at the end.