Seting up Rails development environment on Mac
Let's begin the Ruby on Rails development environment setup on Mac OS X 10.10 Yosemite !!! This will take about 30 minutes.
First we need to install Homebrew , it allows us to install & compile software packages easily from the source.
Open the terminal and run the following command:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Now we have Homebrew installed so we can start with Ruby installation. To manage Ruby versions we will be using rbnev and will run all the commands through terminals.
Run the following commands in your Terminal:
brew install rbenv ruby-build
Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bashprofile
source ~/.bashprofile
Install Ruby
rbenv install 2.2.2
rbenv global 2.2.2
ruby -v
Congrats finally Ruby is installed on your Mac.Now let us start installing Rails.
Its very easy to install Rails...Just type the following commands in your terminal:
gem install rails -v 4.2.3
We can verify Rails is installed by typing the following command:
rails -v
After install Ruby and Rails framework lets start with setting up a Database. Rails default database is sqlite3 , but the problem is that heroku doesn't allows us to deploy the application if the application is made entirely on sqlite3. So we can use MySQL or PostgreSQL.
Let's start with the PostgreSQL setup.
brew install postgresql
Once the action based on this command is completed then follow the instructions and run them.
By default the postgresql user is your current OS X username with no password. So use your username to login to postgresql .
Now you for those who want to use MySQL Databse , follow these instructions:
brew install mysql
The user of mysql is root with no password.
Finally we have completed all the basic steps now lets create a demo application and lets call this application "demoapp".
So follow these simple steps :
rails new demoapp
rails new demoapp -d postgresql if you want to use PostgreSQL as your database or rails new demoapp -d mysql if you want to use MySQL as your database
Now move into the application directory
cd demoapp
If you have setup PostgreSQL or MySQL with a username/password , don't forget to make changes into config/database.yml file , its very important !!!
Now create the database
rake db:create
Finally run the rails local server to check that your application is up and running rails server
Visit http://localhost:3000 to view your new and first rails web application. 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.
Bonjour !!! If you have any doubts do ask me or comment here, i'll try to answer them as quickly as possible :)
