Skip to content

Instantly share code, notes, and snippets.

@azeemh
Last active October 3, 2022 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azeemh/d9ee4ffa2c37984677827567f13da5e3 to your computer and use it in GitHub Desktop.
Save azeemh/d9ee4ffa2c37984677827567f13da5e3 to your computer and use it in GitHub Desktop.
Installing ruby with rbenv on a Mac m2 using a bash terminal (because go rails only has zsh instructions)

Installing ruby with rbenv on a Mac m2 using a bash terminal (because go rails only has zsh instructions)

Change terminal to bash first

chsh -s /bin/bash

Install home-brew using the command from their website (https://brew.sh)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Now that you have homebrew install rbenv with ruby-build

brew install rbenv ruby-build

Add this to your path after installing home-brew and ruby-build I add the following export and eval lines by running

vi .bash_profile

lines to be added to .bash_profile

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

vim noobs press I to go into insert mode and add text. when you are done text editng press ESC to leave insert mode and go back to read only mode. Finally save the file with the changes by pressing Shift+ZZ. (hold shift and press z twice)

Once you have rbenv installed properly and added to your path, You are free to install any version you like (this one is installing version 3.1.2)

rbenv install 3.1.2

Once its installed, if you’d like to set the version to be used in the current directory rbenv local 3.1.2

or if you’d like to set the version to be used everywhere rbenv global 3.1.2

I usually recommend using the latest stable version globally for safety, less vulnerabilities, and bug fixes.

You should be able to see the version you installed by running ruby -v

Github config

git config --global color.ui true
git config --global user.name "yourusername"
git config --global user.email "youremail@youremailprovider.com"
ssh-keygen -t rsa -C "youremail@youremailprovider.com" 

Once you do the above steps, generate an SSH key pair by running the following command and copying the resultant output

cat ~/.ssh/id_rsa.pub

It will generate an ssh key and you can add it to your GitHub account by going to https://github.com/settings/keys and adding a New SSH Key (green button on the top right). enter a name for your key, so you know which computer it is and paste the output you copied from the previous step.

If you did that right, you should be able to run ssh -T git@github.com

And get a similar output: "Hi azeemh! You've successfully authenticated, but GitHub does not provide shell access."

gem install rails -v 7.0.2.4

rbenv rehash

Now you’ll see rails is installed if you run

rails -v

After you’ve setup git and installed rails you’ll want a database.

brew install postgresql

brew services start postgresql

Now if you try generating an application by running rails new testapp -d postgresql you'll still get an error -- in my case it was <NameError: uninitialized constant Gem::Source

to fix this run

gem update --system

Afterwards you should be able to successfully generate a rails application, and install gems without any issue.

at the end of making bash your default shell, installing homebrew, and then rbenv, your .bash_profile will look something like this:

# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment