Cory L
Cory L

Reputation: 273

Installing Ruby on Rails on a new Mac OS Sierra

I am learning to code and trying to make the move for a Rails project from a cloud dev environment to a local one on my Mac with OS Sierra. However, I am having trouble setting up my ruby version and installing rails.

I have installed Homebrew which I used to install rbenv. Using rbenv I have installed ruby 2.4.0 and set it to local and global. I can see it in .rbenv/versions, however when I check my ruby version I still get 2.0.0

$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

When I try and install Rails I get the following;

$ gem install rails
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

I am not sure how I utilize the rbenv ruby version in my system to then install rails.

Upvotes: 1

Views: 1176

Answers (1)

l'L'l
l'L'l

Reputation: 47159

You probably need to add rbenv to your ~/.bash_profile:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile  
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile 

Then source it:

source ~/.bash_profile

Then you can use the rbenv command:

# install a Ruby version:
$ rbenv install <version>

# show versions currently installed and indicate current version
$ rbenv versions

# set ruby version for a specific dir
$ rbenv local <version>

# set ruby version globally
$ rbenv global <version>

# list all available versions:
$ rbenv install -l

The rbenv command is used to install, switch between versions, etc.

Upvotes: 1

Related Questions