How to Install JRuby on Ubuntu — A Complete Beginner‑Friendly Guide
If you’re exploring the Ruby ecosystem but want the power, performance, and JVM compatibility of Java, JRuby is the perfect choice. JRuby is a high‑performance Ruby implementation built on top of the Java Virtual Machine (JVM), making it ideal for enterprise applications, integrations, and high‑throughput systems.
In this blog, I’ll walk you through the JRuby installation process on Ubuntu, along with the prerequisites, verification steps, and common troubleshooting tips.
What is JRuby?
JRuby is an alternative Ruby interpreter that runs on the Java Virtual Machine (JVM). It gives you the flexibility of Ruby with the performance and scalability of Java.
Why JRuby?
Runs Ruby code on the JVM
Integrates with Java libraries
Better performance for multi‑threaded applications
Ideal for enterprise‑level deployments
Works well with tools like Rake, Rails, and Bundler
If you’re already working with Java or JVM‑based systems, JRuby becomes a natural fit.
Step 1: Update Your Ubuntu System
Before installing anything, update your package list:
sudo apt update
sudo apt upgrade -y
This ensures you’re working with the latest repositories.
Step 2: Install Java (JDK)
JRuby requires Java because it runs on the JVM. Install OpenJDK:
sudo apt install openjdk-17-jdk -y
Verify the installation:
java -version
You should see something like:
openjdk version "17.x.x"
Step 3: Download JRuby
You can download JRuby using wget:
wget https://repo1.maven.org/maven2/org/jruby/jruby-dist/9.4.5.0/jruby-dist-9.4.5.0-bin.tar.gz
(Version numbers may change — always check the official JRuby website for the latest release.)
Step 4: Extract the JRuby Package
Extract the downloaded file:
tar -xvzf jruby-dist-9.4.5.0-bin.tar.gz
Move it to /opt (a common location for custom software):
sudo mv jruby-9.4.5.0 /opt/jruby
Step 5: Add JRuby to Your PATH
Open your .bashrc or .zshrc file:
nano ~/.bashrc
Add the following lines at the bottom:
export JRUBY_HOME=/opt/jruby
export PATH=$PATH:$JRUBY_HOME/bin
Reload the file:
source ~/.bashrc
Step 6: Verify JRuby Installation
Run:
jruby -v
You should see something like:
jruby 9.4.x (Ruby 3.x compatible) on Java 17
This confirms JRuby is installed and working.
Step 7: Install RubyGems (Optional but Recommended)
JRuby comes with RubyGems built‑in, but you can update it:
jruby -S gem update --system
Install Bundler:
jruby -S gem install bundler
Step 8: Run a Simple JRuby Program
Create a file:
nano test.rb
Add:
puts "JRuby is working on Ubuntu!"
Run it:
jruby test.rb
If you see the output, your JRuby setup is complete.
Common Issues & Fixes
1. “jruby: command not found”
Your PATH variable is not updated.
Re‑check .bashrc and run:
source ~/.bashrc
2. Java version mismatch
JRuby works best with Java 11 or Java 17. Switch Java versions using:
sudo update-alternatives --config java
3. Permission issues
If JRuby is installed in /opt, ensure correct permissions:
sudo chmod -R 755 /opt/jruby
Final Thoughts
Installing JRuby on Ubuntu is straightforward once you understand the dependencies and environment setup. With JRuby, you get the flexibility of Ruby combined with the robustness of the JVM — a powerful combination for modern development.
Whether you're building microservices, scripting automation, or integrating with Java systems, JRuby gives you a strong foundation.
Note: Image downloaded from Google

Comments
Post a Comment