This lesson is being piloted (Beta version)

DUNE HWDB Training: Building the Ruby Editing Environment

Essential ingredients:

The relavent software for establishing the Ruby editing environment for use with GitHub’s gh-pages are:

Glossary

These glossary items resourced as https://ruby-lang.org/en/documentation/installation

Ruby is used as the programming language to render a web page on the fly. Essential components are selected Ruby Gems which provide the necessary utilities, these include Bundler and Jekyll. To manage the installation of Ruby and matching the associated Gems, ruby-install and chruby have proven useful.

Homebrew will be used for installations in this tutorial.

Follow instructions for installation of Homebrew on macOS if needed.

Homebrew Install Notes

Let’s get started with the macOS package manager Homebrew, realizing first the requirements:

Install Homebrew in one of two ways, first as a build from your Terminal window. Reference: https://brew.sh.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh

or instead with the package (.pkg) installer at https://github.com/Homebrew/brew/releases.

To verify Homebrew installed correctly, in a freshly opened Terminal window, try installing wget (a useful package that can grab a file from its http URL).

$ brew install wget

If Homebrew was installed awhile ago, you might consider upgrading:

$ brew --version
Homebrew 4.0.18
#update packages list
$ brew update
  Downloading... (a whole lot of updating)
#upgrade the packages that have upgrade candidates
$ brew upgrade
   Upgrading ... (a bunch of downloading and upgrading)

Note: The upgrade procedure might include automatic upgrades of Ruby and Gems.

Follow instructions for installation of Ruby 3 on Ubuntu

Ubuntu Install Notes

Updated: April 25, 2024. This was tested on Ubuntu 20.04 running under WSL on Windows 11.

Unfortunately, under Ubuntu 20.04, “apt” only installs Ruby 2.7. To install version 3.+, you must use a separate installer. The following instructions are for using “rbenv” and are summarized from [https://phoenixnap.com/kb/install-ruby-ubuntu] (https://phoenixnap.com/kb/install-ruby-ubuntu).

# Update the system repositories
$ sudo apt update
# Download and install the libraries and compilers Ruby needs to run
$ sudo apt install \
    git \
    curl \
    autoconf \
    bison \
    build-essential \
    libssl-dev \
    libyaml-dev \
    libreadline6-dev \
    zlib1g-dev \
    libncurses5-dev \
    libffi-dev \
    libgdbm6 \
    libgdbm-dev \
    libdb-dev
# Install rbenv from github
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
# Update your bashrc file
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ source ~/.bashrc
# List available versions
$ rbenv install -l
3.0.7
3.1.5
3.2.4
3.3.1
jruby-9.4.6.0
mruby-3.3.0
picoruby-3.0.0
truffleruby-24.0.1
truffleruby+graalvm-24.0.1
# Install Ruby 3
$ rbenv install 3.3.1
# Activate the newly installed version
$ rbenv global 3.3.1
# Check Ruby and Gem versions
$ ruby --version
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]
$ gem --version
3.5.9

Assuming the Homebrew installation or upgrade went smoothly, lets verify a few things with respect to the Ruby programming language. That is, what is the latest version of Ruby, Gem, and Bundler?

Note: A 2.0 version of Ruby is installed on a modern macOS by default, check your via the following commands.

#inspect the whereabouts of your default version of Ruby
$ which ruby
/usr/bin/ruby

$ ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin20]

#verify $HOME gem directory and versions of Ruby installed
$ ls -l ~/.gem/ruby/
drwxr-xr-x   9 daviddemuth  staff  288 Apr 23  2021 2.6.0

#install the latest version
$ brew install ruby
$ ruby --version

$ which ruby && ruby  --version
/usr/local/opt/ruby/bin/ruby
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin20]

# verify RubyGems is installed
$ which gem
/usr/bin/gem
$ gem --version
3.0.3

$ sudo gem update --system

$ which gem && gem --version
/usr/local/opt/ruby/bin/gem
3.5.6

#show local gems installed
$ gem list

#is ruby gem Bundler installed?
$ gem list | grep bundler

# install the bundler gem
$ gem install bundler

#show ruby and gem paths (good for debugging)
$ gem env

With ruby upgraded to a 3. version, and the corresponding gem also upgraded, try launching the localhost web server from the root directory of the github repository you are working from by typing ‘make serve’ at the Terminal command prompt.

If it fails, it might be necessary to install the jeckyll gem, and possibly ruby-install.

Necessary is making sure your PATH to the new ruby and gems installation directories are correct. In your installation log, you might of noticed a few prompts simlar to the following PATH commands, at these to your .bash_profile file located in your $HOME directory (‘ls -a’ to evidenced its existence, .bash_rc, and .profile could also work).

Sniff your installed versions (pay attention to the installation dates for example ‘ls -l’)

#ruby installs for 3/24/24
#set path to GEM EXECUTABLE directory
export PATH="/usr/local/lib/ruby/gems/3.3.0/bin:$PATH"
#set path to RUBY EXECUTABLE directory
export PATH="/usr/local/opt/ruby/bin:$PATH"

Note: Check with ‘$which ruby && ruby –version’ and ‘$which gem && gem –version’ Compare to $ gem env (I noticed a discrepency between the install log recommendation for adding a $PATH to .bash_profile)

Go to your GitHub repository e.g., computing-HWDB

$ cd $HOME/Work/dune/computing-HWDB/

# launch the editing env
$ make serve

With success, the compiling will end with a note to open a web browser, enter the URL: http://localhost:4000/

That terminal window will provide information as you edit your files.

With your emacs window open, edit away. With each file save, the ruby engine will update your view of the webpage with each reopen of the page.

When you are ready to push the update to GitHub, we suggest the use of GitHub Desktop connected to your github account and working in your cloned repository.

ingnore this archive for now…

Archive

# Is the Jekyll gem installed?
$ gem list | grep jeckyll
# install Jeckyll
$ gem install jeckyll
#install latest version of ruby
$ brew install ruby-install
# may need for additional Ruby version installations and control
$ brew install ruby-install
# finding this version of emacs as featureful.
$ brew install spacemacs

Inspect github installation, notice in the root directory of your project installation the file called Gemfile. This file describes the gem dependencies required to run Ruby.

$ more $HOME/Work/dune/computing-HWDB/Gemfile

Updates to this page will follow.

A curiosity is using virtual environments with Ruby, as we do with Python using virtualenv? Reference: https://develves.net/blogs/asd/2016-03-17-using-virtual-environments-ruby-1/. See also https://stackoverflow.com/questions/486995/ruby-equivalent-of-virtualenv.