Step 1: Dependencies for Ruby
Mac
Open terminal
and run the following command to install
# install XCode or GCC to compile native gems
xcode-select --install
# install Homebrew from brew.sh to install libraries and dependencies
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# check if Homebrew is working
brew doctor
Ubuntu/Debian
Open terminal
and run the following command:
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
Windows
In Windows, you have several options. You can decide to opt-in for a Linux conversion using cygwin
, or just install Ruby on your system.
Bare-Windows
Nothing in particular to do. See step 2/bare windows.
Cygwin
Open cygwin and run the following commands
mkdir repositories
cd repositories
mkdir developwithpassion
cd developwithpassion
git clone git://github.com/developwithpassion/devtools
cd devtools
Run the script
./osx_or_cygwin_kick_off
And repeat the above step
Step 2: Installing Ruby
Mac / Linux
For Mac / Linux, you'll want to install rvm
. Type in the following commands
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.3.1
rvm use 2.3.1 --default
Windows
RVM is unavailable on bare-windows, however you can have a look at Ruby versions managers like uru if you like. The following assume you don't use any version manager
Installing Ruby
The Ruby installers can be found on the [Ruby Installer website][2]. In the downloads section you will find the installers for Ruby, pick the appropiate one.
For each version, there are two download links and the one you choose depends on your Operating System.
Windows OS | Download |
---|---|
32 Bits | Ruby 2.3.1 |
64 Bits | Ruby 2.3.1(x64) |
Beware of the most recent versions, as you might run into dependency problems with gems that have not yet been adapted to run under that version of Ruby on windows. At the time of writing, some gems like bcrypt were not yet available for Ruby 2.3+
It is always best to install Ruby in short paths, without accents, without spaces, an remember that on Windows capitalization does not matter. For example the following directory
C:\dev\Ruby22-x64
If this is your only Ruby version, you should add the executables to your PATH during the installation so you can run ruby
or gems
without extra steps. Otherwise you should setup the RUBY_HOME envronment variable, and add %RUBY_HOME%
to your PATH variable.
Now that you've installed Ruby, you can run the ruby -v
command to make sure you have everything installed correctly
ruby -v or rvm current
# ruby-2.3.1
Installing the DevKit
In most cases you will also need the devkit (you can skip this section if you are sure you won't need it). After installing Ruby, download the appropriate version of the devkit and run it using
ruby dk.rb init # Should detect your installed version of RUby, otherwise follow instructions
ruby dk.rb install
Step 4: Installing Rails
Mac / Linux
Rails ships with a lot of dependencies so it's recommended to install a JavaScript runtime like NodeJS
.
This can help speed up your production environment, because you can use CoffeeScript
and the Rails Asset Pipeline. The pipeline minifies JavaScript and CSS files.
To install NodeJS, we're going to add it using the official repository:
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
Now we are ready to Install Rails
gem install rails -v 4.2.6
If installation was successful, the rails -v
command will return the version number
rails -v
# Rails 4.2.6
Windows
If you use Windows, you can use this website to install the full stack, or you will need, like on Linux, to install nodejs and the rails gem.
gem install rails
Note : If you have configured your packet manager on Windows, you can also use Install-Package nodejs
on PowerShell
Step 5: Configuring 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. It will come in handy for the future. Replace my name and email address in the following commands 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 "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"
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.
cat ~/.ssh/id_rsa.pub
Once you've done this, you can check and see if it worked:
ssh -T [email protected]
You should get a message like this
Hi excid3! You've successfully authenticated, but GitHub does not provide shell access.
Step 6: Setting Up MySQL
Rails ships with sqlite3
as the default database. You are free to use a more robust database like MySQL or PostgreSQL, or a non-relational database like MongoDB.
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 file in the future
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
Installing the libmysqlclient-dev
gives you the necessary files to compile the mysql2 gem which Rails uses to connect to MySQL when you setup your Rails app
Step 7: 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 'fakhir' with your username
sudo -u postgres createuser fakhir -s
If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password fakhir
Step 8: Final Steps
And now for the moment of truth. Let's create your first Rails application
#### 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
#### If you want to use another database (especially noSQL/MongoDB)
rails new myapp --skip-active-record
# 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 to view your new website!
Note: If you received an error that said 'Access denied for user 'root'@'localhost' (using password: NO)' then you need to update your config/database.yml file to match the database username and password.
Installing Rails On Ubuntu
On a clean ubuntu, installation of Rails should be straight forward
Upgrading ubuntu packages
sudo apt-get update
sudo apt-get upgrade
Install Ruby and Rails dependecies
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
Installing ruby version manager. In this case the easy one is using rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Installing Ruby Build
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
Restart Shell
exec $SHELL
Install ruby
rbenv install 2.3.1
rbenv global 2.3.1
rbenv rehash
Installing rails
gem install rails
Sign up or log in
Save edit as a guest
Join Stack Overflow
We recognize you from another Stack Exchange Network site!
Join and Save Draft