Im using rbenv as my ruby versioning manager, I run these commands:
$ rbenv install 2.2.2
$ rbenv global 2.2.2
$ rbenv rehash
$ ruby -v
$ > ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin11.0]
but when I run this command:
$ gem -v
it returns an error:
/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv-exec:
/Users/username/.rbenv/versions/2.2.2/bin/gem: /Users/mac/.rbenv/versions/2.2.2/bin/ruby: bad interpreter: No such file or directory
/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv-exec: line 43: /Users/username/.rbenv/versions/2.2.2/bin/gem: Undefined error: 0
What do I miss? thanks in advance
I could not figure the problem out. I was using homebrew and uninstalled it. Reinstalled directly and it's working now.
Related
So I installed the newest version of Ruby:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
By following these steps:
brew install ruby
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
I needed to change the Path so that I could use the newest version of Ruby since if not, whenever I did
ruby -v
It would just take into account the default ruby version I had installed in my MAC:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
Everything works great but I want to install RSpec, so I do:
gem install rspec
This is what I get:
Successfully installed rspec-3.10.0
Parsing documentation for rspec-3.10.0
Done installing documentation for rspec after 0 seconds
1 gem installed
But once I check the version:
rspec --version
This is what I get:
-bash: rspec: command not found
I have uninstalled ruby with brew and installed it again and restarted the terminal but to no avail...Any idea why is this happening? How can I solve it?
Thank you!
It seems that installing Ruby via Home Brew was giving some problems when trying to run RSpec so I uninstalled it and installed it again via RVM. Although, as #Mskha said, Rbenv could also be a possible option.
So, I just updated Ruby version on a CentOS 7 box, to allow for the use of OpenSSL, using this guide:
https://www.server-world.info/en/note?os=CentOS_7&p=ruby23
However, the version is now set to 2.3.8 as per:
$ ruby -v
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
and:
$ which ruby
/opt/rh/rh-ruby23/root/usr/bin/ruby
$ which gem
/opt/rh/rh-ruby23/root/usr/bin/gem
BUT, gem throws the same error as before hand:
$ sudo gem install openssl
ERROR: Error installing openssl:
openssl requires Ruby version >= 2.3.0.
Any ideas?
Try installing gems without sudo. I did such test locally
$ ruby -v
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]
$ sudo ruby -v
sudo: ruby: command not found
Probably your superuser env is not using the same ruby version as your current user's env.
❯ rbenv version
system (set by /Users/eric.nguyen/.rbenv/version)
❯ rbenv local 2.4.2
❯ gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
❯ rbenv global 2.4.2
❯ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
❯ rbenv version
2.4.2 (set by /Users/eric.nguyen/.ruby-version)
❯ gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
❯ gem -v
2.0.14.1
Ruby version is is still 2.0.0p648
I'm on macOS Sierra 10.12.6.
I've done everything mentioned here
I've done:
rbenv rehash
put eval "$(rbenv init -)" in my .zshrc and source ~/.zshrc
put $HOME/.rbenv/shims into $PATH (/Users/eric.nguyen/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/eric.nguyen/Library/Android/sdk/tools:/Users/eric.nguyen/Library/Android/sdk/platform-tools:/Users/eric.nguyen/.rbenv/shims)
But it still doesn't change ruby version.
Restarting my computer resolve the issue.
❯ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
❯ gem -v
2.6.13
You always need to run rbenv rehash after you install a new ruby version using rbenv and also when you install a gem that has a command line options
I am working through NativeScript's set-up on OS X El Capitan and I am stuck at the point where I am supposed to install xcodeproj and cocoapods. Almost everything that I try to do with gem shows the same error:
$ sudo gem install xcodeproj
ERROR: While executing gem ... (Errno::EINVAL)
Invalid argument
The following commands show the same error, wether I run it with sudo or not:
$ gem update --system
$ gem update
$ gem install whatever
$ gem install cocoapods
I have the following versions:
$ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
$ gem --version
2.6.7
I've tried some of the help that I've found online, including reinstalling gem and ruby, restarting but nothing has helped.
I guess that I have a configuration problem with Ruby.
Any suggestions on how to troubleshoot this?
I just had a similar issue after updating everything via Homebrew.
I solved the issue by uninstalling Ruby and installing it via rbenv, then reinstalling cocoa pods.
Steps:
Uninstall ruby
brew uninstall ruby
Install rbenv and ruby-build
brew install rbenv ruby-build
You need to add Ruby to your path.
A. If Terminal is your shell.
Add eval "$(rbenv init -)" to ~/.bash_profile
B. Or if you use another shell
You can find the instruction by entering the command rbenv init NAME_OF_YOUR_SHELL.
Install Ruby
rbenv install 2.3.1
Set the Ruby version
rbenv global 2.3.1
rbenv local 2.3.1
Reinstall Cocoapods
gem install cocoapods
After installing rbenv, I wanted to switch to the correct Ruby version to work on a project, but there seems to be an issue recognizing it.
$ cd project/
$ bundle install
$ Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1
$ rbenv local
$ rbenv: no local version configured for this directory
$ rbenv global
$ 2.1.1
$ ruby --version
$ ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
Am I overlooking something?
There was an issue with my $PATH variable.
This worked for me (in .bash_profile):
export PATH="/usr/local/bin:$PATH"
eval "$(rbenv init -)"