Ruby Version Manager
You might encounter the following error when you try to do gem install
ERROR:  While executing gem ... (NoMethodError)
    undefined method `request' for nil:NilClass
    [@failed_dep.dependency, @activated.request.dependency]
                                       ^^^^^^^^
The error was produced because of the mismatched version of Ruby.
To resolve this error, you can download a Ruby version manager. In this case, I use rbenv
- If you have homebrew installed, you can type this code - brew install rbenvin the terminal
- After installing, check the current ruby version, - ruby -v
 
- Check the path, - which ruby
 
- Run the following to change the path (replace YOUR_USERNAME with your user name, in my case - woodylin@woodys-air ~ %woodylin is my username.)- export PATH="/Users/YOUR_USERNAME/.rbenv/shims:$PATH"
- export PATH="/Users/woodylin/.rbenv/shims:$PATH"
 
- Check the path again, - which ruby
 
- Install the desired version, in my case, - rbenv install 2.7.1
 
- Switch the version - rbenv global 2.7.1
 
- Check the version again - ruby -v
 
- It should output something like this - ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [-darwin21]
 
This change is temporary
If you close the terminal and open it again, the ruby version will go back to the old one. If you do not want that, you can do the following
- rbenv init
- Make sure it's the right path when you run - which rubyyou should see the following- /Users/YOUR_USERNAME/.rbenv/shims/ruby
 
- It adds to your profile so it runs each time you open a new terminal window - echo 'eval "$(rbenv init -)"' >> ~/.zshrc
 
- Finally, run - rbenv local 2.7.1
 
Reference
- Stack Overflow: rbenv not changing ruby version from Promise Preston.
Comments
Post a Comment