How to Install Ruby on Rails on Ubuntu Linux

|

|

This post outlines steps to set up a Ruby on Rails environment on Ubuntu systems. It guides through the process of installing necessary packages including Ruby version 2.5.3, Rails version 5.2.1, and MariaDB, setting up local profile settings using rbenv, and securing the database server with a root password. The post is tailored to assist…

Ruby on Rails is a popular web application framework that allows developers to create complex web applications and websites quickly and easily. Ubuntu Linux is a popular operating system that is widely used for web development.

Installing Ruby on Rails on Ubuntu Linux provides developers with a powerful toolset that enables them to create web applications and websites quickly and efficiently. By installing Ruby on Rails on Ubuntu Linux, developers can take advantage of the many benefits of this framework, including its ease of use, flexibility, and robustness.

Additionally, Ubuntu Linux provides a stable and secure environment for web development, making it an excellent choice for developers who want to build robust and scalable web applications and websites.

These are the packages we’re going to set up.

  • Ruby version 2.5.3
  • Rails version 5.2.1
  • MariaDB

Installing Ruby

You’ll need to install some dependencies to install Ruby and Rails on Ubuntu. To make that happen, install Node.js and Yarn repositories. This will make installing the dependencies easier.

First, install these curl and git packages.

sudo apt update
sudo apt install curl git

Then, run the commands below to add Node.js and Yarn repositories and keys to your system. Then, install some core packages to get your environment going.

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt-get update
sudo apt-get install nodejs yarn zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev

When you’re done, Continue below:

After adding the repositories and installing the necessary packages above, install Ruby with your local profile settings using rbenv. You’ll then use rbenv to install ruby-build.

cd ~/
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

After setting up your local profile, run the commands below to install Ruby version 2.5.3. If a newer version is available, replace the version number with that.

Visit this site to find out Ruby’s latest versions.

rbenv install 2.5.3
rbenv global 2.5.3

To verify that Ruby is installed, run the commands below:

ruby -v

You should see similar lines below:

ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]

Another package management you’ll want to install is bundler. to do that, run the commands below

gem install bundler

Now run the command below after installing the bundler.

rbenv rehash

Install Rails

Now that the Ruby environment is set up run the commands below to install Rails. Rails can be installed from Node.Js. First, run the commands below to install the Node.js repository, then install the Node.js package.

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

Now that Node.js is installed run the commands below to install Rails.

gem install rails -v 5.2.1

Don’t forget to rehash your Rbenv environment and install new packages.

rbenv rehash

To verify if Rails is installed, run the commands below.

rails -v

You should see something similar to the lines below:

Rails 5.2.1

Install MariaDB

Usually, a database server is used for most applications. And MariaDB is an excellent open-source database server. To install it on Ubuntu, run the commands below:

sudo apt-get install mariadb-server mariadb-client libmariadbclient-dev

After installing MariaDB, the commands below can stop, start, and enable the service to start when the server boots.

Run these on Ubuntu 16.04 LTS

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Run these on Ubuntu 18.10 and 18.04 LTS

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Once MariaDB is installed, run the commands below to test whether the database server was installed.

sudo mysql -u root -p

Type the root password when prompted.

The server was successfully installed if you see a similar screen.

After that, Ruby and Rails should be installed, and your environment should be ready for you to start building apps based on Ruby and Rails.

Conclusion:

This post showed you how to install Ruby on Rails on Ubuntu Linux.


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading