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 "[email protected]"
ssh-keygen -t rsa -C "[email protected]"
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 [email protected]
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 -)"