Ruby on Rails on Ubuntu
Ubuntu is a popular platform for Rails development, as are other Unix-based operating systems such as Mac OS X. Installation is relatively easy and widespread help is available in the Rails developer community.
Use a Ruby Version Manager
You’ll need an easy way to switch between Ruby versions. Just as important, you’ll have a dependency mess if you install gems into the system environment. I recommend
RVM to manage Ruby versions and gems because it is popular, well-supported, and full-featured. If you are an experienced Unix administrator, you can consider alternatives such as
Chruby or Sam Stephenson’s
rbenv.
Conveniently, you can use RVM to install Ruby.
Don’t Install Ruby from a Package
Ubuntu provides a package manager system for installing system software. You’ll use this to prepare your computer before installing Ruby. However, don’t use apt-get
to install Ruby. The package manager will install an outdated version of Ruby. And it will install Ruby at the system level (for all users). It’s better to use RVM to install Ruby within your user environment.
Hosted Development
You can use Ruby on Rails without actually installing it on your computer. Hosted development, using a service such as
Cloud9, means you get a computer “in the cloud” that you use from your web browser. Any computer can access the hosted development environment, though you’ll need a broadband connection. Cloud9 is free for small projects.
Using a hosted environment means you are no longer dependent on the physical presence of a computer that stores all your files. If your computer crashes or is stolen, you can continue to use your hosted environment from any other computer. Likewise, if you frequently work on more than one computer, a hosted environment eliminates the difficulty of maintaining duplicate development environments. For these reasons some developers prefer to “work in the cloud” using Cloud9. Cloud9 is a good option if you have trouble installing Ruby on Rails on your computer.
Prepare Your System
You’ll need to prepare your computer with the required system software before installing Ruby on Rails.
You’ll need superuser (root) access to update the system software.
Update your package manager first:
$ sudo apt-get update
This must finish without error or the following step will fail.
$ sudo apt-get install curl
You’ll use Curl for installing RVM.
Install Ruby Using RVM
If you have an older version of Ruby installed on your computer, there’s no need to remove it. RVM will leave your “system Ruby” untouched and use your shell to intercept any calls to Ruby. Any older Ruby versions will remain on your system and the RVM version will take precedence.
Ruby 2.3.1 was current when this was written. You can check for the current
recommended version of Ruby.
RVM will install the newest stable Ruby version.
$ \curl -L https://get.rvm.io | bash -s stable --ruby
Note the backslash before “curl” (this avoids potential version conflicts).
The “—ruby” flag will install the newest version of Ruby.
Check the Gem Manager
Check the installed gem manager version. You may see:
$ gem -v
2.3.1
At the time this was written, a
newer RubyGems version was available. Use
gem update --system
to upgrade the Ruby gem manager:
$ gem update --system
RVM Gemsets
Not all Rails developers use RVM to manage gems, but many recommend it.
Display a list of gemsets:
$ rvm gemset list
gemsets for ruby-2.3.1
=> (default)
global
Only the “default” and “global” gemsets are pre-installed.
If you get an error “rvm is not a function,” close your console and open it again.
Install Bundler
The
Bundler gem is an essential tool for managing gems when developing and running Rails applications.
RVM used to install Bundler automatically. As of version 1.26.11 (released March 31, 2015),
RVM no longer installs Bundler automatically. You must install Bundler:
$ gem install bundler
Nokogiri
Nokogiri is a gem that is a dependency for many other gems. Nokogiri is a gem that requires compilation for your specific operating system. As such, if your system environment doesn’t match Nokogiri’s requirements, compilation of Nokogiri will fail. If your system is configured properly, you’ll be able to compile Nokogiri. However, compilation takes time. Every time you install the Nokogiri gem, you’ll wait (as long as five minutes).
To save time, install the Nokogiri gem in the RVM global gemset:
$ gem install nokogiri
During installation, Nokogiri will display two lengthy messages in the console. It will also pause without displaying any progress for as long as five minutes. Don’t assume installation has failed unless you see an error message or you’ve waited more than ten minutes.
If installation fails, make sure your system is configured properly (look for help on
Stack Overflow).
Rails Installation Options
You can install Rails directly into the global gemset. However, many developers prefer to keep the global gemset sparse and install Rails into project-specific gemsets, so each project has the appropriate version of Rails.
If you install Rails at this point, you will install it into the global gemset.
Instead, make a gemset just for the current stable release:
$ rvm use ruby-2.3.1@rails5.0 --create
Here are the options you have for installing Rails.
If you want the most recent stable release:
$ gem install rails
$ rails -v
If you want the newest beta version or release candidate, you can install with --pre
.
$ gem install rails --pre
$ rails -v
Or you can get a specific version.
For example, if you want the Rails 3.2.18 release:
$ gem install rails --version=3.2.18
$ rails -v
Create a Workspace Folder
You’ll need a convenient folder to store your Rails projects. You can give it any name, such as code/ or projects/. For this tutorial, we’ll call itworkspace/.
Create a projects folder and move into the folder:
$ mkdir workspace
$ cd workspace
This is where you’ll create your Rails applications.
New Rails Application
Here’s how to create a project-specific gemset, installing Rails, and creating a new application.
$ mkdir myapp
$ cd myapp
$ rvm use ruby-2.3.1@myapp --ruby-version --create
$ gem install rails
$ rails new .
Install and set up git
$ sudo apt-get install git
Step 1: Check for ssh keys $ cd ~/.ssh $ ls
Step 2: Generate ssh key $ ssh-keygen -t rsa -C remyasenan@gmail.com Add passphrase
Step 3: Add your ssh key to Github $ sudo apt-get install xclip $ xclip -sel clip <~/.ssh/id_rsa.pub (give the path as .ssh/id_rsa)
- Go to your github profile 'Account Settings'
- Click "SSH Keys"
- "Add SSH key"
- Paste your key(/home/remya/.ssh/id_rsa.pub) into key field
- Click Add
Step 4: Test everything $ ssh -T git@github.com
Install Java
Install Oracle Java Runtime (JRE) in Ubuntu
Ubuntu 12.04 (Precise Pangolin) is right around the corner and requests have been pouring in from our loyal readers. One of those requests is how to install Oracle Java Runtime Environment (JRE) 7 in Ubuntu 12.04. I have written about this topic on this blog previously, but not for Precise Pangolin. This brief tutorial is going to show you how to install it in Ubuntu 12.04 Precise Pangolin if you haven’t already done so.
Objectives:
- Install Oracle Java / JRE in Ubuntu 12.04 (Precise Pangolin)
- Enjoy!
To get started, press Ctrl – Alt – T on your keyboard to open Terminal. When it opens, run the commands below to remove all other installations of OpenJDK from your system.
sudo apt-get purge openjdk*
After that, go and download Java JRE package
from here. When prompted, save the download. Please select the 32 or 64 bit
.tar.gzversion file from the list.
After saving the file, go back to your terminal and run the below commands to extract the java packages you downloaded.
tar -xvf ~/Downloads/jre-7u3-linux-i586.tar.gz
Next, create your java 7 folder by running the commands below.
sudo mkdir -p /usr/lib/jvm/jre1.7.0
Then move all the extracted files and folders into the java 7 folder.
sudo mv jre1.7.0_03/* /usr/lib/jvm/jre1.7.0/
Next, run the commands below to install / update java 7
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jre1.7.0/bin/java 0
Next, create a plugin folder in your home directory by running the commands below.
mkdir ~/.mozilla/plugins
Finally, link the java plugin to your profile.
ln -s /usr/lib/jvm/jre1.7.0/lib/i386/libnpjp2.so ~/.mozilla/plugins/
If your system profile is AMD64, then link java to your profile by running the commands below.
ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
Install IDE
RUBYMINE
Download Rubymine
Open a console and cd into "{installation home}/bin" and type:
./rubymine.sh
SUBLIME
Install via the Package Manager(apt-get):
Simply add to your packages:
For Sublime-Text-2:
$ sudo add-apt-repository ppa:webupd8team/sublime-text-2 $ sudo apt-get update $ sudo apt-get install sublime-text
For Sublime-Text-3:
$ sudo add-apt-repository ppa:webupd8team/sublime-text-3 $ sudo apt-get update $ sudo apt-get install sublime-text-installer
Install Mysql Server
|
- sudo apt-get update
- sudo apt-get install mysql-server
Install Mysql Client
On Ubuntu/Debian and other distributions using aptitude:
sudo apt-get install libmysql-ruby libmysqlclient-dev
If the above command doesn't work because libmysql-ruby
cannot be found, the following should be sufficient:
sudo apt-get install libmysqlclient-dev
Install Mysql Administration and development tool
Go to Ubuntu Software centre and type 'mysql workbench'
Now its almost ready for a rails application to start up for development in your machine.
Get set gooo... :-)