Select Page

Advent

A well-liked internet utility framework, Ruby on Rails was once designed that will help you broaden a hit initiatives whilst writing much less code. With an intention to creating internet building amusing and supported by means of a powerful group, Ruby on Rails is open-source device this is loose to make use of and welcomes contributions to make it higher.

The command-line device RVM (Ruby Version Manager) will provide you with a forged building atmosphere. RVM will can help you arrange and paintings with a couple of Ruby environments and can help you transfer between them. The challenge repository is situated in a git repository.

This educational will take you in the course of the Ruby and Rails set up procedure and arrange by way of RVM

Necessities

This educational will take you in the course of the Ruby on Rails set up procedure by way of RVM. To practice this educational, you wish to have a non-root person with sudo privileges on an Ubuntu 18.04 server.

To discover ways to do so setup, practice our manual initial server setup guide or run our automated script.

Set up

The fastest means of putting in Ruby on Rails with RVM is to run the next instructions.

We first want to replace GPG, which stands for GNU Privacy Guard, to the newest model with a purpose to touch a public key server and request a key related to the given ID.

We’re the use of a person with sudo privileges to replace right here, however the remainder of the instructions can also be accomplished by means of an ordinary person.

Now, we’ll be soliciting for the RVM challenge’s key to signal every RVM unlock. Having the RVM challenge’s public key permits us to ensure the legitimacy of the RVM unlock we can be downloading, which is signed with the matching non-public key.

  • gpg2 --keyserver hkp://keys.gnupg.internet --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Let’s now transfer right into a writable location such because the /tmp listing after which obtain the RVM script right into a record:

We’re going to use the curl command to obtain the RVM set up script from the challenge’s site. The backslash that leads the command guarantees that we’re the use of the common curl command and now not any altered, aliased model.

We will be able to append the -s flag to suggest that the application will have to perform in silent mode together with the -S flag to override a few of this to permit curl to output mistakes if it fails. The -L flag tells the application to practice redirects, and in the end the -o flag signifies to jot down output to a record as a substitute of usual output.

Placing all of those parts in combination, our complete command will seem like this:

  • curl -sSL https://get.rvm.io -o rvm.sh

As soon as it’s downloaded, if you want to audit the contents of the script sooner than making use of it, run:

Then we will pipe it to bash to put in the most recent solid Rails model which may even pull within the related newest solid unlock of Ruby.

  • cat /tmp/rvm.sh | bash -s solid --rails

All the way through the set up procedure, you’ll be induced on your common person’s password. When the set up is whole, supply the RVM scripts from the listing they have been put in, which can usually be on your house/username listing.

  • supply /house/sammy/.rvm/scripts/rvm

You will have to now have a complete Ruby on Rails atmosphere configured.

Putting in Explicit Ruby and Rails Variations

If you wish to have to put in a particular model of Ruby on your utility, slightly than simply the newest one, you’ll achieve this with RVM. First, take a look at to peer which variations of Ruby are to be had by means of list them:

Then, set up the precise model of Ruby that you wish to have thru RVM, the place ruby_version can also be typed as ruby-2.4.0, as an example, or simply 2.4.0:

After the set up, we will checklist the to be had Ruby variations we’ve put in by means of typing:

We will be able to transfer between the Ruby variations by means of typing:

Since Rails is a gem, we will additionally set up quite a lot of variations of Rails by means of the use of the gem command. Let’s first checklist the legitimate variations of Rails by means of doing a seek:

  • gem seek '^rails$' --all

Subsequent, we will set up our required model of Rails. Word that rails_version will simplest discuss with the model quantity, as in 5.1.6.

  • gem set up rails -v rails_version

We will be able to use quite a lot of Rails variations with every Ruby by means of developing gemsets after which putting in Rails inside of the ones the use of the traditional gem instructions.

To create a gemset we can use:

  • rvm gemset create gemset_name

To specify a Ruby model to make use of when making a gemset, use:

  • rvm ruby_version@gemset_name --create

The gemsets let us have self-contained environments for gem stones in addition to have a couple of environments for every model of Ruby that we set up.

Set up JavaScript Runtime

A couple of Rails options, such because the Asset Pipeline, rely on a JavaScript Runtime. We will be able to set up Node.js with the bundle supervisor apt to supply this capability.

Like we did with the RVM script, we will transfer to a writable listing, examine the Node.js script by means of outputting it to a record, then learn it with much less:

  • cd /tmp
  • curl -sSL https://deb.nodesource.com/setup_10.x -o nodejs.sh
  • much less nodejs.sh

After we are happy with the Node.js script, we will set up the NodeSource Node.js v10.x repo:

  • cat /tmp/nodejs.sh | sudo -E bash -

The -E flag used right here will keep the person’s current atmosphere variables.

Now we will replace apt and use it to put in Node.js:

  • sudo apt replace
  • sudo apt set up -y nodejs

At this level, you’ll start checking out your Ruby on Rails set up and begin to broaden internet packages.

How To Uninstall RVM

In the event you not want to use RVM, you’ll uninstall it by means of first casting off the script calls on your .bashrc record after which casting off the RVM information.

First, take away the script calls with a textual content editor like nano:

Scroll all the way down to the place you spot the RVM traces of your record:

~/.bashrc

...
# Upload RVM to PATH for scripting. Be certain that that is the final PATH variable alternate.
export PATH="$PATH:$HOME/.rvm/bin"

Delete the traces, then save and shut the record.

Subsequent, take away RVM with the next command:

At this level, you not have an

Conclusion

We’ve coated the fundamentals of set up RVM and Ruby on Rails right here with the intention to use a couple of Ruby environments.

On your subsequent steps, you’ll be informed extra about working with RVM and how to use RVM to manage your Ruby installations.

In the event you’re new to Ruby, you’ll know about programming in Ruby by means of following our How To Code in Ruby educational collection.

For extra scalability, centralization, and regulate on your Ruby on Rails utility, it’s possible you’ll wish to use it with PostgreSQL or MySQL slightly than its default sqlite3 database. As your wishes develop, you’ll additionally discover ways to scale Ruby on Rails applications across multiple servers.