Você está na página 1de 9

7/27/2017 Setup Ruby On Rails on Ubuntu 15.

10 Wily Werewolf - GoRails


Series (/series) Screencasts (/episodes) Community (/forum) Account (/users/edit)

Setup Ruby On Rails on


Ubuntu 15.10 Wily Werewolf
A guide to setting up a Ruby on Rails development environment

Ubuntu 17.04 (/setup/ubuntu/17.04) Ubuntu 16.10 (/setup/ubuntu/16.10) Ubuntu 16.04 (/setup/ubuntu/16.04)

Ubuntu 15.10 (/setup/ubuntu/15.10) Ubuntu 15.04 (/setup/ubuntu/15.04) Ubuntu 14.10 (/setup/ubuntu/14.10)

Ubuntu 14.04 (/setup/ubuntu/14.04) Ubuntu 13.10 (/setup/ubuntu/13.10) Ubuntu 13.04 (/setup/ubuntu/13.04)

Mac OSX (/setup/osx) Windows (/setup/windows)

Overview

This will take about 30 minutes.

We will be setting up a Ruby on Rails development environment on Ubuntu 15.10 Wily Werewolf.

The reason we're going to be using Ubuntu is because the majority of code you write will run on a Linux server. Ubuntu is one of the easiest Linux
distributions to use with lots of documentation so it's a great one to start with.

You'll want to download the latest Desktop version here: http://releases.ubuntu.com/15.10/ (http://releases.ubuntu.com/15.10/)

Some of you may choose to develop on Ubuntu Server so that your development environment matches your production server. You can nd it on the
same download link above.

Installing Ruby

Choose the version of Ruby you want to install:

2.4.0 (Recommended)

The rst step is to install some dependencies for Ruby.

sudo apt-get update


sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1

Next we're going to be installing Ruby using one of three methods. Each have their own bene ts, most people prefer using rbenv these days, but if
you're familiar with rvm you can follow those steps as well. I've included instructions for installing from source as well, but in general, you'll want to
choose either rbenv or rvm.

Choose one method. Some of these con ict with each other, so choose the one that sounds the most interesting to you, or go with my suggestion,
rbenv.

Using rbenv (Recommended) Using rvm From source

Installing with rbenv is a simple two step process. First you install rbenv , and then ruby-build :

https://gorails.com/setup/ubuntu/15.10 1/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build


echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.4.0


rbenv global 2.4.0
ruby -v

The last step is to install Bundler

gem install bundler

rbenv users need to run rbenv rehash after installing bundler.

Con guring Git

We'll be using Git for our version control system so we're going to set it up to match our Github account. If you don't already have a Github account,
make sure to register (https://github.com). It will come in handy for the future.

Replace my name and email address in the following steps with the ones you used for your Github account.

git config --global color.ui true


git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"
ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"

The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following
command and paste it here (https://github.com/settings/ssh).

cat ~/.ssh/id_rsa.pub

Once you've done this, you can check and see if it worked:

ssh -T git@github.com

You should get a message like this:

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

Installing Rails

Choose the version of Rails you want to install:

5.1.1 (Recommended)

Since Rails ships with so many dependencies these days, we're going to need to install a Javascript runtime like NodeJS. This lets you use
Coffeescript and the Asset Pipeline (http://guides.rubyonrails.org/asset_pipeline.html) in Rails which combines and mini es your javascript to
provide a faster production environment.

To install NodeJS, we're going to add it using the of cial repository:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -


sudo apt-get install -y nodejs

https://gorails.com/setup/ubuntu/15.10 2/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails

And now, without further adieu:

gem install rails -v 5.1.1

If you're using rbenv, you'll need to run the following command to make the rails executable available:

rbenv rehash

Now that you've installed Rails, you can run the rails -v command to make sure you have everything installed correctly:

rails -v
# Rails 5.1.1

If you get a different result for some reason, it means your environment may not be setup properly.

Setting Up MySQL

Rails ships with sqlite3 as the default database. Chances are you won't want to use it because it's stored as a simple le on disk. You'll probably want
something more robust like MySQL or PostgreSQL.

There is a lot of documentation on both, so you can just pick one that seems like you'll be more comfortable with. If you're coming from PHP, you may
already be familiar with MySQL. If you're new to databases, I'd suggest skipping to setting up PostgreSQL.

You can install MySQL server and client from the packages in the Ubuntu repository. As part of the installation process, you'll set the password for
the root user. This information will go into your Rails app's database.yml le in the future.

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

Installing the libmysqlclient-dev gives you the necessary les to compile the mysql2 gem which is what Rails will use to connect to MySQL
when you setup your Rails app.

When you're nished, you can skip to the Final Steps.

Setting Up PostgreSQL

For PostgreSQL, we're going to add a new repository to easily install a recent version of Postgres.

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"


wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev

The postgres installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel
free to replace chris with your username.

sudo -u postgres createuser chris -s

# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password chris

Final Steps

And now for the moment of truth. Let's create your rst Rails application:

https://gorails.com/setup/ubuntu/15.10 3/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails

#### If you want to use SQLite (not recommended)


rails new myapp

#### If you want to use MySQL


rails new myapp -d mysql

#### If you want to use Postgres


# Note that this will expect a postgres user with the same username
# as your app, you may need to edit config/database.yml to match the
# user you created earlier
rails new myapp -d postgresql

# Move into the application directory


cd myapp

# If you setup MySQL or Postgres with a username/password, modify the


# config/database.yml file to contain the username/password that you specified

# Create the database


rake db:create

rails server

You can now visit http://localhost:3000 (http://localhost:3000) to view your new website!

Now that you've got your machine setup, it's time to start building some Rails applications.

If you received an error that said Access denied for user 'root'@'localhost' (using password: NO) then you need to update your
con g/database.yml le to match the database username and password.

35 Comments GoRails Ashok Allu

Sort by Best
Recommend 9 Share

Join the discussion

greymavn 2 years ago


For those who have trouble installing PostgreSQL part on Kubuntu 15.10 :

// remove all installation of postgre first


$ sudo apt-get purge postgresql*

// try changing <precise-pgdg> into <wily-pgdg> on apt sources


$ sudo sh -c "echo 'deb http://apt.postgresql.org/p... wily-pgdg main' > /etc/apt/sources.list.d/pgdg.list"

// install latest version of PostgreSQL (9.4 as it written)


$ sudo apt-get install postgresql libpq-dev
7 Reply Share

Inder singh 9 months ago


If you are using zsh then the commands need to change from .bashrc to .zshrc
Reply Share

Sunil Chandra a year ago

https://gorails.com/setup/ubuntu/15.10 4/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails
Awesome tutorial for beginner
Reply Share

Edwin Ramirez a year ago


Great article, very detailed and very helpful.
Just one thing. I had to change my Gemfile so it didn't use the lastest version of Mysql2> gem 'mysql2', '~> 0.3.18'
Reply Share

Vale Ar a year ago


I struggled a bit with setting up PostgreSQL, but finally got everything running. Thank you!!
Reply Share

i nyoman gurnitha a year ago


How start using MySQL in Ruby on Rails?

I created a new app, using this command "

rails new myapp -d mysql

" as suggested, with no problem.

I setup the database by adding the password and run the server.

But it failed.

Any body can help?

Thanks.
Reply Share

i nyoman gurnitha a year ago


Great tutorials. Many thanks.

Nyoman, Bali, Indonesia


Reply Share

deepanshu sharma a year ago


Getting error while installing rails as follows:-

gem install rails -v 4.2.4


Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

/home/deepanshu/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20160223-5276-sd5elf.rb extconf.rb


checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Reply Share

questjone a year ago


I did all the steps above successfully. However, when launching http://localhost:3000 I get the following error:

Unable to connect
Firefox can't establish a connection to the server at localhost:3000.

Please let me know how to fix it.


Reply Share

questjone > questjone a year ago


Ops, I forgot to create the database and start the server as indicated below. It's working now. Thanks for the great tutorial.

# Create the database


rake db:create

rails server
Reply Share

Junaid Farooq a year ago


Sir why you recommended rbenv?
Reply Share

https://gorails.com/setup/ubuntu/15.10 5/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails

Kyle Larson 2 years ago


Having some issues getting the rvm install 2.2.3 to work.. getting this any idea how to fix?

gh0st@gh0st-Latitude-E7440:~$ rvm install ruby-2.2.3


Searching for binary rubies, this might take some time.
No binary rubies available for: ubuntu/15.10/x86_64/ruby-2.2.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system.................
Error running 'requirements_debian_update_system ruby-2.2.3',
showing last 15 lines of /home/gh0st/.rvm/log/1452785849_ruby-2.2.3/update_system.log
++ case "${TERM:-dumb}" in
++ case "$1" in
++ [[ -t 2 ]]
++ return 1
++ printf %b 'There has been error while updating '\''apt-get'\'', please give it some time and try again later.
404 errors should be fixed for rvm to proceed. Check your sources configured in:
/etc/apt/sources.list
/etc/apt/sources.list.d/*.list
\n'
There has been error while updating 'apt-get', please give it some time and try again later.
404 errors should be fixed for rvm to proceed. Check your sources configured in:
/etc/apt/sources.list
/etc/apt/sources.list.d/*.list

++ return 100
Requirements installation failed with status: 100.
Reply Share

Shefferd > Kyle Larson 7 months ago


I just had the same kind off problems

Your rvm running 'apt-get upgrade' command, you see. Try running the command yourself and see if there any 404 error. There is. Just
remove repos that gives you the error with 'sudo add-apt-repository -- remove ppa:whatever/name' and you are good to go!

Even rvm says you to fix it or comment it out! Hope someone will find it useful
Reply Share

janaka > Shefferd 6 months ago


Shefferd Which command did you mean.
apt-get upgrade or apt-get update command?
Reply Share

Shefferd > janaka 6 months ago


update actually
tnx, for correcting me

the one that fetches the repos or sort of


Reply Share

tldr650 2 years ago


When I goto localhost:3000 I get this error:

raise Gem::LoadError, "Specified '#{spec[:adapter]}' for database adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and
ensure its version is at the minimum required by ActiveRecord)."

Not sure what needs to be done.


Reply Share

privacy id 2 years ago


please update --no-ri --no-rdoc is deprecated, change it to --no-document

http://guides.rubygems.org/...
http://guides.rubygems.org/...
Reply Share

Andr Meireles 2 years ago


Thank you very much.
Rails on Linux Mint 17.3 is up and running!
Reply Share
https://gorails.com/setup/ubuntu/15.10 6/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails
Reply Share

Carlos Pinochet > Andr Meireles a year ago


Hi Andrs, did you install it under root session or under other user?
Reply Share

Eduardo Wichoski 2 years ago


I get this error when i try to create the PostgreSQL user:

createuser: could not connect to database postgres: could not connect to server: No such file or directory

Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

--- EDIT ---

I used "/etc/init.d/postgresql start", then worked.


Reply Share

MAXPAYNE123 > Eduardo Wichoski 2 years ago


Thank you !! Got the same error as you mentioned and your solution worked like a charm :)
2 Reply Share

Eduardo Wichoski > MAXPAYNE123 2 years ago


:)
Reply Share

foxiae > Eduardo Wichoski 2 years ago


How do you change the domain socket?
Reply Share

MoviesTrackr.com 2 years ago


W: Failed to fetch http://ppa.launchpad.net/ch... 404 Not Found

W: Failed to fetch http://ppa.launchpad.net/ch... 404 Not Found

Now What ?
Reply Share

MetaCarpus > MoviesTrackr.com 2 years ago


That repository is outdated. Instead use the official one:

//Remove the old repository


add-apt-repository -y -r ppa:chris-lea/node.js
rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list

//Add the new official repository - Disqus hides the full url, so make sure it's correct:
curl -sL https://deb.nodesource.com/... | sudo -E bash -

//Update repositories
sudo apt-get update

//Install nodejs
sudo apt-get install nodejs
2 Reply Share

Chris Oliver Mod > MetaCarpus 2 years ago

Thanks! I will be updating this to the official nodesource repo soon.


Reply Share

James Tighe 2 years ago


Awesome easy to follow guide! Enabled me to put Ruby on my server without issue!
Reply Share

Abhimanyu Aryan 2 years ago


I should talk to Ruby On Rails community and include your rails installation guides on the official website.
Reply Share

Chris Oliver Mod > Abhimanyu Aryan 2 years ago

I would love that! :)


Reply Share

https://gorails.com/setup/ubuntu/15.10 7/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails

wizzer129 2 years ago


When I do rbenv install 2.2.3 command I get the error: zsh: command not found: rbenv, I am doing the 15.10 install
Reply Share

Johnathan > wizzer129 a year ago


It's because the install above is for bash shell... You will need to replace... ~/.bashrc with.... ~/.zshrc

Like so...

cd
git clone git://github.com/sstephenso... .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
exec $SHELL

git clone git://github.com/sstephenso... ~/.rbenv/plugins/ruby-build


echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.zshrc
exec $SHELL

git clone https://github.com/sstephen... ~/.rbenv/plugins/rbenv-gem-rehash

rbenv install 2.2.3


rbenv global 2.2.3
ruby -v
Reply Share

Bob Smith > wizzer129 a year ago


zsh is probably not there. Try 'sudo apt-get install zsh'
Reply Share

Leo 2 years ago


Likely that if you are using Ruby version 2.2.3 with RVM is bound to have problems when installing libraries that require installing native
extensions. For some reason (IDK if because the RVM's ruby binary is not correctly compiled), when installing ruby 2.2.3 you'll run into that kind
of problems.

The solution I found was installing from source (i.e you compile and install ruby locally on your machine).
To accomplish this do the following:

1. Install Ruby 2.2.3 normally with RVM ("rvm install 2.2.3; rvm use 2.2.3")
2. Once installed issue the command "rvm reinstall 2.2.3 --disable-binary"

Another solution is to fallback to a previous version such as 2.2.2 or 2.2.1

This may be helpful if you run into this problem.

Cheers!
Reply Share

Wayne 2 years ago


Thanks! It's helpful to me.
Reply Share

Bruno Paulino 2 years ago


Thanks for this amazing tutorial! you just described every step!
Reply Share

Subscribe d Add Disqus to your siteAdd DisqusAdd Privacy

(/)
2014-2017, Chris Oliver. (http://excid3.com)
LEARN EXTRAS ABOUT
Series (/series) Deploy Rails (https://hatch.gorails.com) Feedback
Episodes (/episodes) Pricing (/pricing) (http://gorails.uservoice.com/forums/259979-
Community (/forum) Testimonials (/testimonials) general)

https://gorails.com/setup/ubuntu/15.10 8/9
7/27/2017 Setup Ruby On Rails on Ubuntu 15.10 Wily Werewolf - GoRails

Guides (/guides) Blog (/blog) Terms (/terms)


Courses (https://courses.gorails.com/) Privacy (/privacy)
About Us (/about)
Icons by Icons8 (https://icons8.com)

Join the newsletter Follow @excid3 (https://twitter.com/excid3) Tweet (https://twitter.com/share)

https://gorails.com/setup/ubuntu/15.10 9/9

Você também pode gostar