4

I have tried to install rails multiple times, but I keep getting this error. Also, whenever I update ruby to version 3.1 and set the global install to 3.1, I receive this message stating I am still on 2.6. I use MacOS and homebrew too.

ebirch@Ejs-MacBook-Pro ~ % sudo gem install rails
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.
Ej Birch
  • 67
  • 6
  • Your path must be using the system Ruby before the Brew Rubies. I'd recommend some form of Ruby version manager (rvm, rbenv, asdf, etc) or at the least updating your path. – Dave Newton May 02 '22 at 18:18
  • 1
    Update to ruby 3.7? but how if last stable version [is 3.1.2](https://www.ruby-lang.org/en/downloads/releases/) – Alter Lagos May 02 '22 at 22:45
  • I meant to put 3.1 you're right. Sorry for the incorrect information. – Ej Birch May 02 '22 at 22:51

4 Answers4

2

Based on your brief context I am gonna assume you're not using a tool such as rbenv or RVM and am gonna recommend these.

I would recommend to go with a guide like this (instead of reading the above tools docs): https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-macos Basically until step 3 there is good enough and you just change the versions of ruby and rails to whatever you need.

Note (since I saw another answer mentioning conda): conda is also a more general (not specific to ruby) environment manager and if that works for you great too.

draganstankovic
  • 5,382
  • 1
  • 27
  • 33
2

You might have to re-download ruby in order to get the newest version. Ruby just came out with a new update about a couple of months ago and it is not compatible with the older version of rails

juliavolpe
  • 43
  • 5
2

Follow the next steps to set up rbenv, ruby 3.1.2, and rails.

Step 1

brew install rbenv

Step 2 Add the following lines to your .zshrc file

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

Step 3

brew update && brew upgrade ruby-build

Step 4

rbenv install 3.1.2
rbenv global 3.1.2

Step 5

gem install rails
1

How about using conda?

$ brew install --cask miniconda
$ conda init bash            # from then on your bash shell will be `(base) ... $`
# in `base` you are in normal global environment
# indicating that you are in base conda environment
$ conda activate --name ruby # create environment for ruby
$ conda activate ruby        # enter the 'ruby' environment
$ conda install -c conda-forge ruby=3.7  # install ruby 3.7 into this environment 'ruby'

# you can any time get out of 'ruby' environment by:
$ conda deactivate

# you can 'see' your ruby 3.7 only if you enter the 'ruby' environment by
$ conda activate ruby
# as soon as you deactivate this environment, you will see your normal global ruby, when calling ruby.

Learn about usage of conda in https://www.youtube.com/watch?v=YJC6ldI3hWk .

Gwang-Jin Kim
  • 9,303
  • 17
  • 30