Tutorial

How To Install Ruby on Rails on FreeBSD 10.1 using RVM

Published on June 11, 2015
How To Install Ruby on Rails on FreeBSD 10.1 using RVM

Introduction

Ruby on Rails, or RoR for short, is a very popular full-stack web application development framework written in Ruby. It allows you to rapidly develop web applications that conform to the MVC (model-view-controller) pattern.

This tutorial will cover how to set up a Ruby on Rails development environment using RVM on your FreeBSD 10.1 server.

Note: As of July 1, 2022, DigitalOcean no longer supports FreeBSD Droplets through the Control Panel or API. However, you can still spin up FreeBSD Droplets using a custom image. Learn how to import a custom image to DigitalOcean by following our product documentation.

Prerequisites

Before you begin, all you need is:

  • A FreeBSD 10.1 server.

  • A user with root privileges. (The default freebsd user is fine.)

Step 1 — Setting bash as the Default Shell

This tutorial will use the Ruby Version Manager, or RVM for short, to install Ruby. Because RVM works best with bash 3.2.25 or higher, in this step, we will install bash and set it as the default shell.

Before we begin, log into your FreeBSD 10.1 server.

  1. ssh freebsd@your_server_ip

Next, install the latest version of bash using pkg.

  1. sudo pkg install bash

We’ll need to add a line to /etc/fstab for bash to work. Open the file using ee or your favorite text editor.

  1. sudo ee /etc/fstab

Add the line fdesc /dev/fd fdescfs rw 0 0 to the end of the file as shown below.

/etc/fstab
# Custom /etc/fstab for FreeBSD VM images
/dev/gpt/rootfs /       ufs     rw      2       2
/dev/gpt/swapfs none    swap    sw      0       0
fdesc	/dev/fd		fdescfs		rw	0	0

Save and exit the file, then mount the new entry.

  1. sudo mount -a

Now that bash is installed, set it as your default shell using the chsh command.

  1. sudo chsh -s bash

To start using bash, log out and log back in to your server. If you don’t want to log out, you can start a bash session manually by typing in:

  1. bash

Step 2 — Installing RVM

In this step, we will install RVM.

To download the RVM installer, you first need to install curl.

  1. sudo pkg install curl

Move to the /tmp directory.

  1. cd /tmp

Download the RVM installer script from https://get.rvm.io.

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

Finally, use the script to install the latest stable release of RVM.

  1. bash installer.sh stable

Because RVM makes a few changes in your shell’s startup configuration, the recommended way to activate those changes is by logging out of your current session and logging back in. Alternatively, you can apply the changes to your current session manually by running:

  1. . ~/.rvm/scripts/rvm

Step 3 — Installing Ruby

You can now use RVM to install any version of Ruby. Because 2.2.2 is the latest stable version available as of June 2015, we’ll install this version.

  1. rvm install 2.2.2

This will take a moment. Once the installation completes, list the rubies available on your system.

  1. rvm list

If your installation was successful, you will see:

rvm list output
rvm rubies

=* ruby-2.2.2 [ i386 ]

# => - current
# =* - current && default
#  * - default

To confirm that Ruby 2.2.2 is present in your $PATH, type in:

  1. ruby -v

You should see a message that looks like this:

ruby -v output
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-freebsd10.1]

Step 4 — Installing Ruby on Rails

In this step, we will install Ruby on Rails.

Because Ruby on Rails is a gem, it can be easily installed using RubyGems (Ruby’s package management framework) using gem install rails. However, this installation will take a while to complete because it includes lots of other gems (some of which need to be compiled) and their documentation files. You can speed up this command considerably by adding the --no-rdoc --no-ri flags, which will skip the documentation installation.

Install Ruby on Rails, optionally without documentation.

  1. gem install rails --no-rdoc --no-ri

For the Rails Assets Pipeline to work, a Javascript runtime should be present on your server. The easiest way to get one is by installing Node.js using pkg.

  1. sudo pkg install node-devel

Step 5 — Creating a Test Project

Now that the Rails installation is complete, let’s test it by creating an empty project inside the /tmp directory.

If you’re not still in the /tmp directory, change to it.

  1. cd /tmp

Use the rails command to create a new project called test-project (or whatever you like).

  1. rails new test-project

Enter the project directory.

  1. cd test-project/

And finally, try starting the Rails console.

  1. rails c

If your Rails installation was successful, you should see the following prompt:

rails c prompt
Loading development environment (Rails 4.2.1)
2.2.2 :001 >

You can exit the prompt by entering exit.

  1. exit

Conclusion

In this tutorial, you learned how to set up Ruby on Rails on your FreeBSD 10.1 server. You can now use your FreeBSD server as a development environment for your Rails projects!

While doing so, you also learned how to install Ruby using RVM. If you want to learn more about RMV, check out this tutorial on how to use RVM to manage your Ruby environments.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Hathy A

author


Default avatar

staff technical writer

hi! i write do.co/docs now, but i used to be the senior tech editor publishing tutorials here in the community.


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

For some reason I’m not able to run rvm/script file.

I was taking a look to the file at https://github.com/rvm/rvm/blob/master/scripts/rvm and when I check my $BASH_VERSION I don’t get any output. Mine Bash is not well setup.

I’m running a script that install ruby and puppet. But I’m stuck with ruby to do the installation in one step, I can’t logout and loging.

https://github.com/killua99/packer-templates/blob/freebsd-10.1-x86_64/freebsd-10.1-x86_64/scripts/puphpet.sh

I try to change the shebang to any thing I could think and nothing make the $BASH_VERSION be there.

How is possible you could install it?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel