Installing Ruby-on-Rails For MacOS

Installing Ruby-on-Rails

For MacOS:

Enter the commands in a terminal without typing the beginning $ sign. Make sure that (1) you are using Mac OS (latest version Catalina is best; upgrade your terminal from bash to zsh as recommended) (2) you have admin privilege.

Precaution: One of those silly things? your MacOS account name (not your full name) has to be one word. Open a terminal and execute the pwd command and check the account name. In my case, I see /Users/mtirfan, which means that my account name is mtirfan. The account name has to be one single word without any spaces. Otherwise, any script will fail to recognize paths correctly. There's a way of fixing it, as shown here. Check out the account name johnappleseed there which is one word and matches the home folder name. Follow the procedure outlined there for changing the home folder name followed by changing the account name. These two names must be the same (case-sensitive). Restart the computer.

1. Install homebrew: installing Rails (and numerous other packages) becomes easy if you have homebrew installed. To check whether you have it installed, enter the following command: $ brew --version

If it throws an error, you don't have homebrew. In that case, install homebrew using the following command.

$ /bin/bash -c "$(curl -fsSL )"

2. Update homebrew: Even if you had homebrew installed beforehand, update your version of homebrew and upgrade all the packages it installed by running the following command. $ brew update && brew upgrade

Also run the following to check any issues with homebrew. Follow the suggestions shown. $ brew doctor

To be conservative, restart your computer. It resolves issues with not restarting the terminal properly.

3. Install rbenv, a Ruby version manager. Install rbenv. $ brew install rbenv ruby-build

Look at the output in the terminal and strictly follow all the suggestions. If you get a message telling you to add export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$

(brew --prefix openssl@1.1)" to ~/.zshrc (or ~/.bash_profile for older MacOS), do the following (replace ~/.zshrc by ~/.bash_profie as needed).

Run the command open ~/.zshrc. If ~/.zshrc does not exist, run touch ~/.zshrc to create the file first before opening it. Insert the line export RUBY_CONFIGURE_OPTS="--withopenssl-dir=$(brew --prefix openssl@1.1)" at the end of the file (in a new line), and save the file.

Similarly process all suggested edits to ~/.zshrc, including inserting the export CPPFLAGS or export LDFLAGS if you are told to do so.

Make sure rbenv loads every time you open a terminal. Here, we are assuming zsh is your terminal. If you are using bash terminal, replace ~/.zshrc with ~/.bash_profile in the following two commands. $ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc

Execute the .zshrc script. $ source ~/.zshrc

To be conservative, you may restart your computer to make sure that all open terminals are restarted properly (not required).

Install Ruby. This will not interfere with the MacOS's version of Ruby. The minus ell term in the first line lists the latest stable versions. Choose one (I'm choosing 3.0.1). $ rbenv install -l $ rbenv install 3.0.1

Make rbenv's Ruby version the default Ruby. $ rbenv global 3.0.1

Check the version. It should be 3.0.1. $ ruby -v

4. Install Rails. Run the following command. $ gem install rails

If you get any permission error, then run the following commands [replace mtirfan by your user name]: $ sudo chown -R mtirfan /Users/mtirfan/.rbenv $ gem install rails

Manually update rbenv. $ rbenv rehash

Check the version of rails.

$ rails -v

5. Install Database. Mac already has SQLite installed. The following command installs a Ruby gem for Ruby to connect to SQLite. $ gem install sqlite3

6. Set Up the Server. Run the following two commands. Strictly follow all instructions on screen. $ brew install yarn

For Windows:

1. First, install SQLite DBMS: Extract the contents of the zip file "sqlite-dll-win64-x64-3310100.zip" from https://

download.html into Ruby's bin folder. For example, I've copied the DLL and the DEF files into my Ruby's bin folder, which is "C:\Ruby200-x64\bin". If later on you get an error message, build sqlite from the source and do the installation following the 9 steps from "". (Note that you may omit Step 1, as you have already installed Ruby development kit while installing Ruby.)

2. Run the following command. Folder names like Ruby200-x64 might be different in your computer. $ gem install sqlite3 --platform=ruby -- --with-sqlite3-include=c:\Ruby200x64\sqlite3\include --with-sqlite3-lib=c:\Ruby200-x64\sqlite3\lib --with-sqlite3-dir=c: \Ruby200-x64\sqlite3\bin

3. Run the following command to install rails. $ gem install rails

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download