Setting Up Ruby, RubyGems, and Build-Essential for Jekyll
This guide provides a step-by-step approach to setting up Ruby, RubyGems, and essential tools for a Jekyll environment on Linux (ubuntu).
Step 1: Install Ruby and RubyGems
Ruby is the programming language required to run Jekyll, and RubyGems is the package manager for Ruby. Here’s how to set them up:
- Update the System Package List:
1
sudo apt update
- Install Ruby (using
ruby-full
):1
sudo apt install ruby-full
- What happens:
- This installs Ruby and its package manager, RubyGems.
- Ruby binaries are placed in
/usr/bin
or/usr/local/bin
, which are system-wide directories already in thePATH
.
- Verify Installation:
1 2
ruby -v gem -v
- You should see the versions of Ruby and RubyGems, confirming the installation.
- What happens:
Step 2: Install Supporting Tools
Ruby and RubyGems require certain tools and libraries to compile and run gems. These are: build-essential, and zlib1g-dev
- Install Build-Essential:
1
sudo apt install build-essential
- What is installed:
- Compilers like
gcc
,make
, and related tools needed to compile software and Ruby gems with native extensions.
- Compilers like
- Where it is installed:
- Binaries are placed in
/usr/bin
(e.g.,/usr/bin/gcc
).
- Binaries are placed in
- What is installed:
- Install zlib Development Files:
1
sudo apt install zlib1g-dev
- What is installed:
- The zlib compression library, used by Ruby and other programs for handling compressed files.
- Where it is installed:
- Libraries are stored in
/usr/lib
, and headers are in/usr/include
.
- Libraries are stored in
- What is installed:
Step 3: Understanding and Adding to PATH
The PATH
environment variable defines where the system looks for executable files when you type a command.
How PATH
Works
- When you type a command (e.g.,
ruby
), the system searches for the corresponding executable in the directories listed in thePATH
.- Example of
PATH
:1
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
- The directories are checked in order. The first match is executed.
- Example of
- If an executable is not in a directory listed in
PATH
, you’ll get an error like:1
command not found
Step 4: Configuring RubyGems for User-Specific Installation
RubyGems is a package manager for Ruby (like apt for Ubuntu). You’ll use it to install Jekyll.
By default, RubyGems installs gems globally (e.g., /usr/local/lib/ruby/gems
). This requires sudo
and affects all users.
Even though it’s technically optional in some scenarios, adding ~/gems/bin
to PATH
is highly recommended for the following reasons:
- Convenience: Avoid installing RubyGems packages (called gems) as the root user. Allows you to run commands (like jekyll, bundler) directly without specifying full paths.
- Best Practice: Encourages the use of user-specific installations (
gem install
withoutsudo
), which is safer and avoids modifying system-wide directories. - Future-Proofing: If you install more gems later, you won’t need to keep worrying about their paths.
To allow user-specific installations:
- Set
PATH
:- Add the following lines to your
~/.bashrc
:1 2 3
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc
- Apply the changes:
1
source ~/.bashrc
- What this does:
GEM_HOME
: Specifies the directory (e.g.,~/gems
) where RubyGemsgem
will install gems for the current user.PATH
: Ensures the system can locate executables installed by RubyGemsgem
in~/gems/bin
.
- Add the following lines to your
- Effect on the System:
- When
GEM_HOME
is set:- Gems are installed in
~/gems
instead of system-wide directories. - The user can install gems without
sudo
, and each user has their own isolated gem environment.
- Gems are installed in
- Adding
~/gems/bin
toPATH
ensures that gem executables (e.g.,jekyll
,bundle
) can be run directly.
- When
Final Steps: Installing Jekyll and Bundler
After setting up Ruby, RubyGems, and updating your PATH
, follow these steps to complete the Jekyll setup:
- Install Jekyll and Bundler Gems:
1
gem install jekyll bundler
- Installs
jekyll
andbundler
in~/gems
ifGEM_HOME
is set.
- Installs
- Check the Executables Directory:
1
ls $HOME/gems/bin
- You should see the
jekyll
andbundler
executables listed here.
- You should see the
- Verify
PATH
Includes~/gems/bin
:1
echo $PATH
- Confirm that
~/gems/bin
appears in the output. If not, update yourPATH
.
- Confirm that
- Run an Installed Gem:
1
bundler -v
- This should display the installed version of Bundler, confirming the installation was successful.
Summary
- Ruby and RubyGems:
- Ruby binaries are typically located in
/usr/bin
or/usr/local/bin
. - RubyGems
gem
is bundled with Ruby and is used to manage gem installations.
- Ruby binaries are typically located in
- Essential Supporting Tools:
- Build-essential: Required for compiling software and some gems.
- zlib1g-dev: Provides compression support required by some gems.
- Adding
~/gems/bin
toPATH
:- Ensures gem executables (like
jekyll
andbundler
) can be run directly from the terminal.
- Ensures gem executables (like
- User-Specific vs System-Wide Installations:
- Setting
GEM_HOME
enables user-specific installations, avoiding system-wide conflicts and the need forsudo
.
- Setting