Ruby Rails For Mac Os X



  • How to Install Ruby on Mac OS X with RVM. This article explains why you should avoid using the version of Ruby bundled with Mac OS X and should instead install your own version of Ruby with RVM, the Ruby Version Manager. Hands Off the System Ruby. Apple bundles the Ruby programming language with OS X. However, the main caveat for using the.
  • Upgrade Your System to OS X Mavericks. Installing Ruby on Rails is simple, but unless you.
  1. Ruby Rails For Mac Os X64
  2. Chrome For Mac Os X
  3. How To Update Mac Os X

Last modified: Thu Aug 16 2018 22:49:02 GMT+0800 (Malay Peninsula Standard Time)

This will take about 30 minutes. We will be setting up a Ruby on Rails development environment on macOS 10.15 Catalina. Older versions of OS are mostly compatible so follow along as far as you can and then Google search for any problems you run into.

Chapter 3. MacOS Installation Guide

The following guide was tested only on machine running MacOS Sierra (10.12). If you are using older version of MacOS, this tutorial may not work. At the time this tutorial is being written the latest stable Ruby version for MacOS is Ruby 2.4.0. If any of the command require you to match the Ruby version that you have downloaded, change the version accordingly.

3.1 Ruby Installation

Open a terminal as shown in Figure 3.1.1.

Figure 3.1.1: Terminal Window icon in Applications

The root directory of the terminal as shown in Figure 3.1.2 is your Home directory.


Figure 3.1.2: Terminal Window in MacOS Sierra

By default, modern MacOS come preinstalled with Ruby. To check your Ruby version, enter the command below.

ruby -v

After the command above is inserted, you will see the Ruby version on your terminal window. Figure 3.1.3 shows the terminal window with Ruby version 2.0.0 returned to the terminal window.


Figure 3.1.3: Ruby version

The default Ruby version, Ruby 2.0.0. is old. The latest stable Ruby version for MacOS when this tutorial is written is Ruby 2.4.0. To update your Ruby in your Mac to the latest version, enter the command below. Figure 3.1.4 shows the output after the command is entered into the terminal window.

curl -sSL https://get.rvm.io | bash -s stable --ruby


Figure 3.1.4: Updating Ruby version

If you do not have XCode installed in your machine, a window will pop up and ask you to see if you would like to install XCode. XCode and Git command line are part of the developer tools required in order to update Ruby on your machine. Select Install, as shown in Figure 3.1.5, to install the required files and enter your admin password in the terminal window.


Figure 3.1.5: XCode installation window pop up and Admin password request

A License Agreement window, as shown in Figure 3.1.6 will then pop up. Press 'Agree' to continue.


Figure 3.1.6: License Agreement window

Ruby Rails For Mac Os X

If you received Return Error 1 message as shown in Figure 3.1.7, skip to Chapter 3.2. However, if you received an output as shown in Figure 3.1.8, you have successfully updated your Ruby version to Ruby 2.4.0 (as shown in the console output).


Figure 3.1.7: Status 1 error message


Figure 3.1.8: Ruby 2.4.0 installed successfully

Now, set Ruby 2.4.0 as your default Ruby version, enter the command below. Figure 3.1.9 shows the default Ruby version is set to Ruby 2.4.0. If you are not using Ruby 2.4.0, change the number in the command according to the version shown in Figure 3.1.8. If the code does not return a correct Ruby version, please repeat the installation process: rvm use 2.4 --default

To check your updated Ruby version, use the command ruby -v.


Figure 3.1.7: Ruby 2.4.0 is set as default Ruby version

Proceed to Chapter 3.3 to install Rails.

3.2 Homebrew Installation

If you received Return Error 1 message as shown in Figure 3.2.1, continue reading. If not, proceed to Chapter 3.3 to install Rails.


Figure 3.2.1: Status 1 error message

The reason this error shows up is because you do not have Homebrew installed. To fix this, install Homebrew by entering the command below into your terminal. A confirmation screen, as shown in Figure 3.2.2, will display all the files and scripts that will be installed on your machine. Press return key to install the files.

ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'


Figure 3.2.2: Homebrew installation confirmation screen Iringer download for mac.

If your machine is password protected, you will asked to enter your password next. Figure 3.2.3 shows the password request window.


Figure 3.2.3: Password request window

Figure 3.2.4 shows Homebrew is installed successfully to your machine. Now, update your Ruby by repeating the process as discussed in Chapter 3.1.


Figure 3.2.4: Homebrew installed successfully

3.3 Rails Installation

To download Rails, enter the code below in a Terminal Window. Figure 3.3.1 shows the input and the output text from the Terminal. This operation can take up to 5 minutes depending on your computer’s processing speed and Internet connection.

gem install rails


Figure 3.2.1 Input and the output text from the Terminal

After the installation is complete, run the following code to check if Ruby is installed successfully. Figure 3.2.2 Rails version in the Terminal Window. If the code does not return a Rails version, please repeat the installation process.

Ruby Rails For Mac Os X64

rails -v


Figure 3.2.2: Rails version shown in Terminal Window

3.4 Create a Rails Application

To create your website, it is highly recommending to create a folder name Code in the Ruby file directory. The purpose the folder Code is to store all your source code folder. The Ruby folder location may vary depending on your Operating System Architecture.

Enter the folder Code and create a sample application name Blog. Enter the following command to command line window a similar output as shown in Figure 3.4.1 below will be generated.

rails new Blog


Figure 3.4.1 Generating a new Blog

3.5 Start your server

To start the Web Server, navigate to the folder of your code and run the follow command below. Figure 3.5.1 shows a Rails server is running.

rails s


Figure 3.5.1: A Rails server is running

Insert the URL in your Web Browser based on what you have seen from the Terminal Window to visit your website. Figure 3.5.2 shows a running Ruby on Rails website. Based on the Figure 3.5.1, localhost:3000 is the path to my website.


Figure 3.5.2 A working Ruby on Rails website

3.6 Generate a simple MVC

A second command line window is opened to prevent termination of local Web Server. To verify that Ruby and Rails were installed correctly without any errors, use the scaffold command to generate a simple set of a model, views, and controller for Rails Application.

rails g scaffold User name:string age:integer Angel photo frame free download.

A similar output as shown in Figure 3.6.1 will be generated from the command line tool.

Figure 3.6.1: Output of terminal window when a scaffold command is used.

Run the command rake db:migrate to migrate the database generated by the command scaffold to local database server. A similar output as shown Figure 3.6.2 will be generated from the command line tool.


Figure 3.6.2: Output of terminal window when a migrate command is used.

Navigate to the index page of newly generated page by entering the path at your browser. The index page of Users will be generated as shown in Figure 3.6.3.

localhost:3000/users


Figure 3.6.3: Users index page

To make sure that the application is working and does not throw any error when new data are committed to the database, press the link New User create a new sample data set. A form will be rendered a shown in Figure 3.6.4. Populate the form with any sample data that you prefer and press Create User.


Figure 3.6.4: New user form

An alert message, as shown in Figure 3.6.5, User was successfully created alert message will be shown on the screen when the data is inserted into the database successfully.


Figure 3.6.5: User was successfully created alert

To redirect to the index page of Users, press the Back button located under the Age shown in Figure 3.6.5. By looking at Figure 3.6.6, we can see that the Users index page was being rendered.


Figure 3.6.6: Users index page was rendered from output log

Figure 3.6.7 shows a picture of Users index page with the data that populated in the form earlier.


Figure 3.6.7: Users index page

Congratulation, you have successfully installed Ruby on Rails on your own machine!

(Related article: How to Install Ruby on Rails for Linux (Ubuntu))

Step 1. Upgrade Your System to OS X Mavericks

Installing Ruby on Rails is simple, but unless you have an old Mac machine (a pre ‘08 model), you should seriously consider upgrading your system to OS X Mavericks (10.9). It comes with the latest improvements from Apple, and it’s completely free! You can follow this guide for this upgrade.

Step 2. Install XCode Command Line Developer Tools

We need to first install Apple’s XCode Command Line Developer Tools, so that we can use the build tools and utilities that come with it to build Ruby gem native extensions and install other system packages.

This used to be a lengthy process, but if you are on Mavericks, all you have to do is to run this command in your terminal:

After the installation, type

and if the response has something like Apple LLVM version 5.0, you are all set.

Step 3. Install Homebrew

Homebrew is the best package manager on Mac. If you are still using MacPorts, it’s time to start brewing! To install homebrew, use this one line installer:

After it finishes, type

you should see the response as /usr/local/bin/brew

Step 4. Install Ruby with RBENV

Your Mac already ships with Ruby (we used it to install homebrew in the last step). However, it’s still a good idea to use a Ruby version manager because:

  • the system Ruby is likely outdated and you may want to use the latest Ruby version to leverage the new features
  • you may need to work on multiple projects on different Ruby Versions

RVM and RBENV are the two leading Ruby version managers. I prefer RBENV because it’s a simpler and lighter weight solution, and together with bundler, it solves the project gemset problem in a more elegant way.

We can just use homebrew to install rbenv.

rbenv by itself only manages switching ruby versions. ruby-build and rbenv-gem-rehash are both rbenv plugins. ruby-build allows you to install rubies with rbenv and rbenv-gem-rehash automatically hashes new gems for you when they are installed. You can see here to learn more about rbenv plugins.

You need to initialize rbenv by adding this line in your ~/.bashrc file.

Now you are ready to install Ruby with rbenv. At the time of this writing, the latest stable Ruby version is 2.1.0, so let’s install that.

Step 5. Install Git and Set Up Github Account

Git is the version control system of choice for the Ruby community. If you followed this guide, you should already have git installed as part of the XCode Command Line Developer Tools. You may also want to install git separately with homebrew for easier upgrading.

Now tell git your name and email that it will use for your commits.

Github is the leading platform for source code hosting and collaboration. If you don’t have an account yet, go ahead and sign up for one at https://github.com. Make sure you sign up with the same email address from the step above.

For easier authentication with Github when you push or pull code, follow this guide to set up ssh keys for your Mac. Kodi krypton 17.6 apk.

Step 6. Create a New Rails Application

If you don’t have a directory to hold all your development projects yet, you can create that directory like below:

Now you can create a Rails project in that directory:

Wait until the the last step finishes, and you just created your first Rails project! You can verify that you set up Rails by first starting the server

Now open up your browser and type in the address bar http://localhost:3000 and if you see a welcome page, your app is running locally.

Step 7. Set Up Sublime Text as Code Editor

If you already have an editor of choice, such as Vim or Emacs, you can skip this step. :) If you are not familiar with code editors, Sublime Text is an excellent choice and you can download it here.

After you install it, run the following command:

and now you can simply type

in your Rails project directory to start coding.

The convention for Ruby programs is to use two spaces as indentation. You can follow Sublime Text 2 => Preferences => Settings - User and add these lines.

Optional Step 1. Use iTerm 2, zsh and oh-my-zsh to set up an awesome terminal

Download and Install iTerm 2. It comes with more features and is easier to customize than the built in Terminal.

Now it’s time to customize your terminal! Here are some of my preferences.

  • Under “General”, check “Copy to clipboard on selection”
  • Under “Profile” => “Colors”, click on “Load Presets”, then choose “Dark Background”
  • Under “Profile” => “Text”, change the font to one that you enjoy looking at. My favorite is 20pt Anonymous Pro with Anti-aliased. You have to download it first and install it into your Mac’s font book before you can use it
  • Under “Keys”, define a hotkey to hide/show the terminal window. This is much faster than having to Command+Tab through opened windows and find iTerm 2

Zsh is an alternative shell to the default bash shell that comes with Mac. It adds nice features such as smart tab completions, but what really sets it apart is its scriptability. Together with oh-my-zsh, an open source zsh configuration management framework, it becomes really easy to customize both the look and functionality of your terminal.

Your Mac already comes with zsh. To use zsh, go to iTerm 2 => Preferences => Profiles => General and in the “Command” section, select “Command”, and type /bin/zsh in the box after it. Now close your terminal and relaunch it, you should be on zsh!

Next, let’s install oh-my-zsh:

Now you can customize the ~/.zshrc file.

Chrome For Mac Os X

  • If you have your settings in ~/.bash_profile, you may want to copy them over to /.zshrc.
  • Find the plugins=(git) line and add more plugins. Here is the plugins I am using:

If you do not like the default theme, you can pick from one of the many themes that come with oh-my-zsh. You can see the list of themes here and here.

If you feel really adventurous, you can even build your own theme! Take a look at how themes are implemented, and copy/tweak/build one exactly to your taste!

Optional step 2. Install Postgresql as a production quality database

By default, Rails uses sqlite3 as the default development database. It’s a nice database but probably not one that you want to use in production. Postgresql is a solid, production quality relational database and works well with Rails. It’s generally a good idea to set up your local database to match the database on the production environment.

The easiest way to use Postgresql on Mac is to download and install the Postgres.app

How To Update Mac Os X

With Postgresql running, add gem 'pg' to the Gemfile in your rails project and run bundle install to install the Postgresql Ruby driver. This RailsCast talks about how to set up with Postgres in detail. You can skip the “taps” part if you don’t already have data that needs to be migrated.

Congratulations!

This is it! You just made it to the end of our first rails tutorial, and have now set up your local Ruby on Rails development environment like a pro, now it’s time to start coding. :)