ruby installation with rbenv - ruby

I installed Ruby with rbenv. When trying to install Rails using gem install rails I get:
ERROR: Failed to build gem native extension.
I suspect that there is a conflict with my Ruby versions.
rbenv local and rbenv global are set to 1.9.3-p327, but if I type ruby -v I get "ruby 1.8.7".
How can I change this to 1.9.3?
echo $PATH:
/usr/local/opt/rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Try:
rbenv local 1.9.3-p327
and then
rbenv rehash just to be sure.
Also, you can set 1.9.3-p327 as the default with:
rbenv global 1.9.3-p327

Related

Error installing pg, requires Ruby version >= 2.2 even if ruby is >=2.2

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
$ which ruby
/usr/local/rvm/rubies/ruby-2.7.2/bin/ruby
$ which gem
/usr/local/rvm/rubies/ruby-2.7.2/bin/gem
$ sudo gem install pg
ERROR: Error installing pg:
pg requires Ruby version >= 2.2.
Error installing pg, requires Ruby version >= 2.2 even if ruby is >=2.2.
When using RVM, it is necessary for some environment variables to be loaded to RVM (and RVM-installed Rubies) to find its code.
When running your gem install command with sudo however, sudo will reset your $PATH and unset the required environment variables before executing the gem command with the sanitized $PATH. With that, you will likely use your system ruby rather than your RVM-installed ruby.
In general, you should not use sudo to install Rubies or any gems when using RVM. Instead, you generally can and should just use your normal user.
If you do have to use sudo with RVM for some reason, there is a special rvmsudo command which retains your RVM environment in the evaluated context. See https://rvm.io/integration/sudo for details. However, as written above, you should try to avoid using this!

Ruby gem show "Invalid argument" error for almost every command

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

bundler, command not found

I wanna use the bundler, but after I installed rbenv, ruby and bundler, it still tells me command not found.
$ rbenv version
2.2.3 (set by /Users/khlee/.rbenv/version)
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
$ export GEM_HOME=$HOME/Software/ruby
$ gem install bundler
Successfully installed bundler-1.12.5
Parsing documentation for bundler-1.12.5
1 gem installed
$ rbenv rehash
$ bundle install
-bash: bundle: command not found
Execute below command and check list of gem in gemset:
rbenv gemset list
May be budler gem is not installed in current gemset.

Installing gems to which Ruby with rbenv

How does one control which Ruby a gem is installed to using rbenv? Or could there be a central place accessible to all Rubies? I am just running Ruby scripts not Rails. rbenv-gemset seems to be for that?
The gem is installed into whatever your currently selected Ruby is. E.g.
rbenv shell 2.0.0-p247
gem install bundler # bundler is installed for Ruby 2.0.0-p247 only
rbenv shell 1.9.3-p447
gem install bundler # bundler is installed for Ruby 1.9.3-p447 only
Just to add on: rbenv-gemset would be for organizing your gems within the same ruby version. Only rbenv controls which ruby you install your gems to...

RVM bundle not found

I just installed rvm and then the bundler gem.
➜ ~ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.7.0]
➜ ~ gem list|grep bundler
bundler (1.0.12)
But when I try to run the bundle command then I got the following error:
➜ ~ which bundle
bundle not found
The interesting thing is that it works if I prepend "rvm ruby"
➜ ~ rvm ruby bundle
Still, I don't think like I should prepend rvm ruby before any command. Is this behavior correct?
EDIT: apparently the problem is that the default configuration is not remembered between shells.
If I type "rvm 1.8.7 --default" then it works, but as soon as I open a new shell it doesn't.
Run $ rvm use 1.8.7 and you should be good. The reason for this is that rvm will use the system ruby/gems unless you specify otherwise. You can verify this by running which ruby and checking the path.
You can set the default ruby with rvm as well, like so: $ rvm --default use 1.8.7.
My problem was that I had .rvm/bin on my path on .zshrc, which was causing all kind of troubles
This works for me :
rvm gemset list
rvm gemset use global
More details here : http://marcgrabanski.com/gem-management-with-rvm-and-bundler/

Resources