Install Ruby on Rails in Ubuntu 15.04

Source: Internet
Author: User
Tags rehash version control system ruby on rails

Install Ruby on Rails in Ubuntu 15.04

In this article, we will learn how to use rbenv to install Ruby on Rails in Ubuntu 15.04. We chose Ubuntu as the operating system because Ubuntu is an operating system with many packages and complete documents in the Linux release, so I think this is the right choice. If you have not installed the latest Ubuntu, you can start by downloading the iso file.

 

Install Ruby

The first thing we need to do is update the Ubuntu package and install some dependencies for Ruby.

  1. sudo apt-get update
  2. sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

There are three ways to install Ruby: rbenv, rvm, and source code installation. Each has its own advantages, but recently developers prefer to use rbenv instead of rvm and source code for installation. We will install the latest Ruby version 2.2.2.

There are only two simple steps to install rbenv. Step 1 install rbenv, followed by ruby-build:

  1. cd
  2. git clone git://github.com/sstephenson/rbenv.git .rbenv
  3. echo 'eval "$(rbenv init -)"'>>~/.bashrc
  4. exec $SHELL
  5. git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
  6. echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"'>>~/.bashrc
  7. exec $SHELL
  8. git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
  9. rbenv install 2.2.2
  10. rbenv global2.2.2
  11. ruby -v

We need to install Bundler, but we need to tell rubygems not to install local documents for each package before installation.

  1. echo "gem: --no-ri --no-rdoc">~/.gemrc
  2. gem install bundler

 

Configure GIT

Before configuring git, you need to create a github account. You can register a github account. We need git as the version control system, so we need to set it to match the github account.

Replace the following Name and Email address with your github account.

  1. git config --global color.ui true
  2. git config --global user.name "YOUR NAME"
  3. git config --global user.email "[email protected]"
  4. ssh-keygen -t rsa -C "[email protected]"

Next, add the new ssh key to the github account. In this way, you need to copy the output of the following command and paste it in the setting page of Github.

  1. cat ~/.ssh/id_rsa.pub

If you have done this, check whether it is successful.

  1. ssh -T git@github.com

You should get the following information.

  1. Hi excid3!You've successfully authenticated, but GitHub does not provide shell access.

 

Install Rails

We need to install a javascript runtime environment like NodeJS, because Rails is becoming more and more dependent recently. In this way, we can merge and compress your javascript to provide a faster production environment.

We need to add PPA to install nodeJS.

  1. sudo add-apt-repository ppa:chris-lea/node.js
  2. sudo apt-get update
  3. sudo apt-get install nodejs

If you encounter a problem during the update, you can try this command:

  1. # Note the new setup script name for Node.js v0.12
  2. curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
  3. # Then install with:
  4. sudo apt-get install -y nodejs

Next, run this command to install rails:

  1. gem install rails -v 4.2.1

Because we are using rbenv, use the following command to make rails executable programs usable.

  1. rbenv rehash

To ensure that rails has been correctly installed, you can run rails-v, which is shown as follows:

  1. rails -v
  2. # Rails 4.2.1

If you get a different result, it may be that the environment is not correctly set.

 

Set MySQL

Maybe you are familiar with MySQL. you can install the MySQL client and server from the Ubuntu repository. You can set the root user password during installation. This information will be stored in the database. yml file of your rails program in the future. Run the following command to install mysql.

  1. sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Install libmysqlclient-dev for mysql2 gem compilation. When setting a rails program, rails uses it to connect to mysql.

 

Last step

Let's try to create your first rails program:

  1. # Using a MySQL database
  2. rails new myapp -d mysql
  3. # Go To The application directory
  4. cd myapp
  5. # Creating a database
  6. rake db:create
  7. rails server

Visit http: // localhost: 3000 to access your new website. Now you can build a rails program on your computer.

If you encounter the error message "Access denied for user 'root' @ 'localhost' (Using password: NO)" when creating a database, you need to update your config/database. yml file to match the user name and password of the database.

  1. # Edit database. yml in the configuration folder
  2. nano config/database.yml

Enter the password of the MySql root User.

Exit (Ctrl + X) and save.

 

Summary

Rails is written in Ruby and is also a programming language used with rails. In Ubuntu 15.04, Ruby on Rails can be installed using rbenv, rvm, and source code. In this article, we use rbenv and MySQL as the database. If you have any questions or suggestions, please note them in the comment bar.

Important article: Ruby-Linux/Windows installation, code development, and Rails practice

Ruby on rails:



Build Ruby On Rails in Ubuntu

Build Ruby on Rails on Ubuntu 13.10

Ruby on Rails 4 Tutorial Chinese Version HD complete PDF

CentOS6.5 use Nginx + Passenger to deploy the Ruby on Rails Environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.