Ruby on Rails, often simply Rails, is an open source web application framework which runs on the Ruby programming language. It is a full-stack framework: it allows creating pages and applications that gather information from the web server, talk to or query the database, and render templates out of the box. As a result, Rails features a routing system that is independent of the web server.
Ruby on Rails emphasizes the use of well-known software engineering patterns and principles, such as active record pattern, convention over configuration (CoC), don’t repeat yourself (DRY), and model/view/controller (MVC).
This article applies to all releases of Ubuntu so it should help you to install Ruby on Rails on Ubuntu 12.04 LTS, 13.10 and any future releases. The majority of articles regarding this subject are release specific and very long. We’ll keep this one short and simple!
Update and Prepare System
It is important to make sure that your server is updated. On Ubuntu servers, you will need to run the following commands to update your repositories and your system. We’ll also need some basic requirements on your server.
$ apt-get update
$ apt-get upgrade
$ apt-get -y install curl
Install Ruby and Rails
We will be leveraging the RVM project to help us install the latest Ruby release. When we will install RVM, we will tell it to compile and install the latest Ruby release and download Rails as well.
$ curl -sSL https://get.rvm.io | bash -s stable --rails
RVM will automatically download, install and compile the latest release of Ruby. Once it’s done with that process, it will install the latest release of rubygems
which is required to install Rails. Afterwards, it downloads and installs Ruby on Rails on your server.
You can now use Ruby on Rails by typing the rails
command in your SSH shell, you will see output similar to the following:
$ rails
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /usr/local/rvm/rubies/ruby-2.1.0/bin/ruby
-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
-B, [--skip-bundle] # Don't run bundle install
-G, [--skip-git] # Skip .gitignore file
[--skip-keeps] # Skip source control .keep files
-O, [--skip-active-record] # Skip Active Record files
-S, [--skip-sprockets] # Skip Sprockets files
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
-J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository
-T, [--skip-test-unit] # Skip Test::Unit files
[--rc=RC] # Path to file containing extra configuration options for rails command
[--no-rc] # Skip loading of extra configuration options from .railsrc file
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Suppress status output
-s, [--skip] # Skip files that already exist
Rails options:
-h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
Your Ubuntu machine now has the latest Ruby and Ruby on Rails installed on it without worrying about installing dependencies and complicated compilation processes, all it took was one short command!