Support Online
Skip to main content

Installing Ruby on Rails with rbenv on Debian 8

💡 What You Will Learn in This Guide

This guide is prepared for developers who want to install a Ruby on Rails development environment on the Debian 8 operating system. Proceeding step by step:

  • will install rbenv and ruby-build plugins,
  • Manage Ruby versions,
  • Will install Rails and necessary Gem packages,
  • With Node.js integration, you will activate the JS features of Rails.

🧠 Technical Summary

This guide is based on the rbenv tool, which makes Ruby version management easier. The goal is to run multiple Ruby projects on a single server without version conflicts. The implementation process consists of 5 stages: system dependencies, rbenv installation, Ruby installation, Rails installation and JavaScript Runtime integration.


⚙️ 1. Update System Dependencies

In the first step, update the system packages and install the necessary dependencies:

sudo apt-get update
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev git-core

This command installs the core libraries required for Ruby compilation and rbenv installation.


🧩 2. Installing rbenv and ruby-build

rbenv lets you manage Ruby versions in isolation.

Clone the rbenv repository:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv

Update your PATH variable:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

This step ensures that rbenv commands are recognized in the terminal.

To verify the installation:

type rbenv

Expected output:

rbenv is a function

Install the ruby-build plugin:

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

ruby-build allows you to easily download and install Ruby versions.


💎 3. Installing Ruby

List the installable Ruby versions (optional):

rbenv install -l

Install Ruby 2.3.3:

rbenv install 2.3.3
rbenv global 2.3.3

Verify Ruby version:

ruby -v

Expected output:

ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]

This will set Ruby 2.3.3 as the system-wide default.


📦 4. Gem Packages and Rails Installation

Speed up installations by turning off gem documentation:

echo "gem: --no-document" > ~/.gemrc

Install Bundler:

gem install bundler

Bundler is used to manage application dependencies.

Install Rails:

gem install rails

Update rbenv commands:

rbenv rehash

Verify Rails version:

rails -v

This command indicates that Rails has been installed successfully.


⚙️ 5. JavaScript Runtime (Node.js) Installation

Rails needs a JavaScript environment for the Asset Pipeline feature. Node.js provides this functionality.

Add the NodeSource repository and install Node.js:

curl -sSL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

This command installs Node.js 6.x and enables Rails JS rendering.


🔄 6. rbenv Update

To update rbenv to the latest version:

cd ~/.rbenv
git pull

The current rbenv version supports new Ruby versions and includes bug fixes.


🧹 7. Uninstalling Ruby Versions

To purge old Ruby versions:

rbenv uninstall 2.1.3

This way, only the Ruby versions you are actively using remain in the system.


❓ Frequently Asked Questions (FAQ)

1. Is it mandatory to use rbenv?

No, but recommended. rbenv allows you to seamlessly manage different Ruby versions in different projects.

2. What is a Gem?

It is a reusable software package in Ruby. Rails is also distributed as a Gem.

3. What does rbenv rehash do?

When a new Gem or Ruby version is installed, rehashing is required for the commands to be recognized in the terminal.

4. Why is Node.js needed?

Some features of Rails (e.g. webpacker and assets) require JavaScript Runtime.

5. Why is the build-essential package important?

It contains the necessary compilation tools to compile languages such as Ruby from source code.


🎯 Result

Installation of rbenv and Ruby on Rails on Debian 8 is now complete. You can manage Ruby versions and run your Rails projects with Node.js support. 💡 You can create a secure, optimized and scalable development environment by hosting your application on the GenixNode platform.