Installing Ruby 2.3 on WSL (Windows Subsystem for Linux)

2 min read 07-10-2024
Installing Ruby 2.3 on WSL (Windows Subsystem for Linux)


Installing Ruby 2.3 on WSL (Windows Subsystem for Linux)

The Windows Subsystem for Linux (WSL) provides a powerful environment for developers to run Linux applications directly on Windows. If you need to work with Ruby 2.3 for a specific project or compatibility reason, installing it on WSL is a straightforward process. This article guides you through the steps, ensuring you have Ruby 2.3 up and running in your WSL environment.

Setting the Stage

Let's start by assuming you have WSL installed and a Linux distribution of your choice running. If not, follow the instructions to install WSL here. For this example, we'll be using Ubuntu, but the process is similar for other distributions.

Open your WSL terminal and let's dive into the installation.

Original Code

# Update your package lists
sudo apt update

# Install the required dependencies
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libffi-dev libxml2-dev libreadline-dev

# Download Ruby 2.3.x source code
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.8.tar.gz

# Extract the source code
tar -xzf ruby-2.3.8.tar.gz

# Navigate to the extracted directory
cd ruby-2.3.8

# Configure Ruby
./configure --enable-shared

# Build Ruby
make

# Install Ruby
sudo make install

# Verify installation
ruby -v

Understanding the Code

The provided code snippet above uses the standard approach for compiling and installing Ruby from source. Let's break it down:

  1. sudo apt update: This command refreshes your package list, ensuring you have the latest available information for installing required packages.
  2. sudo apt install -y build-essential zlib1g-dev ... libreadline-dev: This line installs various essential development tools and libraries, including those required for compiling Ruby.
  3. wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.8.tar.gz: This command downloads the source code for Ruby 2.3.8 (you can choose the specific version you need).
  4. tar -xzf ruby-2.3.8.tar.gz: This command extracts the downloaded source code archive.
  5. cd ruby-2.3.8: We navigate to the directory containing the extracted source code.
  6. ./configure --enable-shared: This command prepares Ruby for compilation on your system, specifying that we want to build a shared library.
  7. make: This command compiles the Ruby source code.
  8. sudo make install: This command installs the compiled Ruby binaries and associated files to the system.
  9. ruby -v: This command verifies the installation by displaying the installed Ruby version.

Additional Tips

  • Alternative Installation Methods: While the manual installation from source provides complete control, you might consider using a package manager like RVM (Ruby Version Manager) or rbenv for easier management of multiple Ruby versions.
  • Environment Variables: Setting environment variables like PATH can improve your development workflow by making Ruby commands accessible from anywhere in your terminal.
  • Gem Installation: Once Ruby is installed, you can install gems (Ruby packages) using the gem install command. For example, gem install rails would install the Ruby on Rails framework.
  • Troubleshooting: If you encounter any issues, check your network connection, ensure the necessary packages are installed, and refer to the official Ruby documentation for further assistance.

Conclusion

Installing Ruby 2.3 on WSL provides you with a powerful toolset for developing web applications and other projects. By following the outlined steps and utilizing the additional tips, you can successfully set up Ruby 2.3 on your WSL environment.

Remember to keep your WSL environment updated and consult the official Ruby documentation for the latest information and best practices. Enjoy coding in the world of Ruby!