Installing Ruby on Rails in Yosemite is easy, but there are a couple of steps. This article will walk you through those steps. Let's get started.
|Operating System||Mac OS X 10.10.x Yosemite|
|Last Update||2/15/2015 7:01pm EST|
Step 1: Install Homebrew
Homebrew is a popular platform that is used to compile and install open source applications. We will use Homebrew to install a number of different applications. To install Homebrew, open a Terminal (Choose Utilities from the Go menu, then find the Terminal Application in the list.) and copy/paste the following command and press enter.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
A software installation window should come up, wait for it to complete, then switch back to the Terminal window and press enter. You'll then be prompted to enter your password, do so and press enter. Homebrew should now be installed. Next run the following command to ensure that Homebrew is properly installed.
You should receive a message saying that
Your system is ready to brew. This indicates that Homebrew is set up properly and ready to use..
Step 2: Install rbenv and ruby-build
Now that we have Homebrew installed, we can install rbenv and ruby-build. rbenv is an awesome tool that is used to manage different Ruby versions and ruby-build is a plugin that allows you to install specific ruby versions right from the command line. To install them both run the following command.
brew install rbenv ruby-build
Step 3: Installing Ruby
Now we are ready to install Ruby. First, run the following command to get a list of all of the Ruby versions. You can optionally skip this step and just install 2.2.0, but depending on how old this article is, 2.2.0 may eventually be out of date.
rbenv install -l
You should see a large list of ruby versions, scroll up until you see versions that start with a number. The highest number corresponds to the latest version. As of this writing there is 2.2.0 and 2.3.0-dev. We want 2.2.0 because it's stable. Now run the following command to install 2.2.0.
rbenv install 2.2.0
After some time the new version of Ruby will be installed. Now run the following command to set it as the default Ruby.
rbenv global 2.2.0
Step 4: Installing a Database.
Next we need to install a database server. I've included instructions for both MySQL as well as PostgreSQL below. If you unsure which to choose, chose PostgreSQL. It tends to be the more popular option in the Ruby on Rails world. You can always come back and install MySQL later if needed.
You can skip this section if you are installing MySQL. To install PostgreSQL, run the following command.
brew install postgresql
After a bit of time, PostgreSQL will be installed. Next run the following command to add it to your startup.
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Next run the following command to start PostgreSQL.
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
By default, the a user is created with your OS X username and no password. You can type whoami to get this username.
You can skip this section if you are using PostgreSQL. To install MySQL, run the following command.
brew install mysql
After a bit of time MySQL will be installed, next run the following command to have it run on login.
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Now run the following command to start MySQL.
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Now we need to finish the setup of the MySQL server by setting a root password and removing anonymous users, etc. Run the following command to do this.
- First, you will be prompted to enter the root password. The default root password is blank, so just push enter.
- You will then be prompted to set a root password. Press y, push enter, and set the root password.
- Next you will be prompted to remove anonymous users. Press y and push enter.
- Next you will be prompted to disallow remote root login. It is recommended that you do this unless you have need to access your database remotely using root. Press y unless you wish to allow remote root access and push enter.
- For the next 2 prompts (test database and reload privileges) press enter.
Great! Now MySQL is installed and ready to use.
Step 5: Set Up Git
Next we need to set up git. First, set your name and email with the following commands. Replace 'Your Name' and [email protected]' with your own name and email.
git config --global user.name “Your Name“ git config --global user.email [email protected]"
Next we need to generate an ssh key. Run the following command to generate an ssh key.
If you want to use a passphrase, enter one when prompted, otherwise just press enter. After the key is generated you can then run the following command to view your public key.
From there you can add it to Github, Bitbucket, or some other service.
Step 6: Install Rails
Installing Rails is simply a matter of running the following commands
gem install rails
This will install the latest stable version of Rails.
If creating a new rails app, make sure to specify the database engine with the
Terminal Commands for For MySQL Based Apps:
rails new myapp -d mysql
Terminal Commands for For PostgreSQL Based Apps:
rails new myapp -d postgresql
That's it, thanks for reading!