Saturday, April 15, 2017

Installing Ruby on Rails 5.0.2 on Ubuntu Linux 16.04 LTS

I could not find an one-stop comprehensive webpage that explains how to install Ruby on Rails on Ubuntu Linux from start to finish by searching on Google. However the approximate procedures that I did for my computer from the sources that I summarized from several webpages:

1. Install Gem:
  • Check if gem is installed on Ubuntu Linux:
  • In Terminal (shell) type:
gem
  • If gem is not install, install it by typing:
sudo apt-get install rubygems

2. Install Ruby dependencies:
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-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs

3. Install Git (if it has not been installed):
sudo apt-get install git

4. I installed Ruby 2.4.0 by choosing the rbenv method:
  • I typed the following commands line by line in Linux shell:
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

5. Install Bundler
gem install bundler

6. Configuring Git
  • If you don't have a Github account, register one
  • Replace my name and email address with yours
git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"

7. To install NodeJS
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs


8. Installing Rails
  • I installed Rails 5.0.1
gem install rails -v 5.0.1
  • If you're using rbenv, you'll need to run the following command to make the rails executable available:
rbenv rehash
  • Check Rails version
rails -v
# Rails 5.0.1
?. Setting Up MySQL
  • A friendly reminder: I just pressed the Enter key when prompted for the MySQL root password and later I found out that I cannot use MySQL without root password. Then, I think I need to completely purge MySQL and then do the install again, which is very difficult.
  • If you want to install MySQL, 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 file in the future.
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
9. Setting Up PostgreSQL
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-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

10. Final Step - Test the first Rails website
  • Originally, Rails shipped with SQLite, which is good for simple database applications
  • In Linux Terminal (shell), to create a new project Project named "myapp":
rails new myapp
  • Change to directory "myapp":
cd myapp
  • In the "myapp" directory, create a database:
rake db:create
  • Start the Rails server:
rails server
  • Using Firefox or your favorite browser, visit http://localhost:3000 to view your first Ruby on Rails website.

11. If you want to use PostgreSQL
  • Add the -d postgresql when creating a new Rails project:
# 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

# Start the rails server
rails server



12. To stop the Rails server
  • In the terminal (shell) windows, press Ctrl + C on the keyboard
 

References:
Debian / Ubuntu: Install gem The FrontEnd To Rubygems
https://www.cyberciti.biz/faq/debian-ubuntu-install-gem-the-frontend-to-rubygems/

Setup Ruby On Rails on Ubuntu 16.04 Xenial Xerus
https://gorails.com/setup/ubuntu/16.04

How To Install Git on Ubuntu 14.04
https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-14-04

5 comments:


  1. thanks for sharing such details about ruby on rails Programming.
    It is the interseting topic and to get some important information.on Ruby on Rails Online Training Bangalore

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thanks for sharing this blog post,Nice written skill
    selenium Online Training

    ReplyDelete
  4. Thanks for sharing this blog post,Nice written skill
    selenium Online Course

    ReplyDelete

How to kill an abandoned process in Linux/Unix

I remembered it, then I forgot, then I remembered it, and then I forgot again. In case of a Linux/Unit process hang, I have to figure out ...