Ruby on Rails is a widely-used, open-source application stack that simplifies web app development. It is built on the Ruby programming language and follows the Model-View-Controller (MVC) architectural pattern. With its ease of use and extensive community support, Ruby on Rails has become a popular choice for building websites and web applications for brands like Github, Airbnb, and Soundcloud.
In this tutorial, we will guide you through the process of installing Ruby on Rails on a Debian 11 system. Debian is a Linux distribution known for its stability and reliability, making it an excellent choice for hosting Ruby on Rails applications.
Before we begin, make sure you have a Debian 11 server with root access.
Prerequisites
To install Ruby on Rails on Debian 11, you’ll need the following prerequisites:
- A Debian 11 server
- Root access to the server
Install RVM
RVM (Ruby Version Manager) is a command-line tool that allows you to manage multiple Ruby environments on your system. It simplifies the installation and management of different Ruby versions.
To begin, log in to your Debian 11 server as the root user and update the system packages:
apt update
apt upgrade -y
Once the system is up to date, install the necessary dependencies:
apt install gnupg2 curl wget -y
Now, import the RVM GPG key:
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Next, download and run the RVM installation script:
curl -sSL https://get.rvm.io | bash -s stable --ruby
Once the installation is complete, load the RVM system path:
source /usr/local/rvm/scripts/rvm
Verify the RVM version:
rvm version
You should see the installed version of RVM.
Install Ruby Using RVM
After installing RVM, it’s time to install Ruby. First, update RVM to the latest version:
rvmget stable --autolibs=enable
Next, add the root user to the RVM group:
usermod -a -G rvm root
Now, install the latest version of Ruby:
rvm install ruby-3.0.2
Make Ruby the default version:
rvm --default use ruby-3.0.2
Verify the Ruby version:
ruby --version
You should see the installed version of Ruby.
Install Node.js and Yarn
To process JavaScript files in your Ruby on Rails applications, you’ll need to install Node.js. Additionally, we’ll install Yarn, a package manager for JavaScript.
Start by installing the required dependencies:
apt install gcc g++ make -y
Next, add the Node.js repository:
curl -sL https://deb.nodesource.com/setup_14.x | bash -
Add the Yarn repository:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
Update the repository and install Node.js and Yarn:
apt update
apt install nodejs yarn -y
Verify the Node.js version:
node --version
You should see the installed version of Node.js.
Verify the Yarn version:
yarn --version
You should see the installed version of Yarn.
Upgrade RubyGems
RubyGems is a package manager for Ruby. We’ll update it to the latest version:
gem update --system
Verify the RubyGems version:
gem -v
You should see the updated version of RubyGems.
To disable the installation of Ruby package documentation, run the following command:
echo "gem: --no-document" >> ~/.gemrc
Install Ruby on Rails
With Ruby and its package manager updated, we can now install Ruby on Rails. Use the following command:
gem install rails-v6.1.4
Once the installation is complete, verify the installed version of Rails:
rails -v
You should see the installed version of Rails.
Create a Project with Ruby on Rails
Now that Ruby on Rails is installed, let’s create a new project. Navigate to the desired location where you want to create the project and run the following command:
rails new project
Replace “project” with the name of your project.
Change into the project directory:
cd project
To ensure that all project files are present, run the following command:
ls
You should see a list of project files and folders.
To start the Puma Rails web server, use the following command:
rails s -b 69.87.221.117 -p 8080
Replace “69.87.221.117” with your server’s IP address.
You should see the server starting up and listening on port 8080.
Conclusion
Congratulations! You have successfully installed Ruby on Rails on Debian 11. You can now start creating web applications using the power of Ruby on Rails. If you encounter any issues during the installation process, feel free to refer to the official Ruby on Rails documentation or seek support from the vibrant Ruby on Rails community.
At Shape.host, we provide reliable and scalable cloud hosting solutions, including Linux SSD VPS, perfectly suited for hosting Ruby on Rails applications. Our services are designed to empower businesses with efficient and secure hosting options. Start your Ruby on Rails journey with Shape.host today!