Why can't I install Gosu into my rbenv Ruby? - ruby

I installed rbenv yesterday to install Gosu.
I followed "How to Install Rbenv on OS X" and everything worked fine.
Today, I started a new Gosu project, and it gave me this error:
my_game.rb:1:in `require': no such file to load -- gosu (LoadError)
from my_game.rb:1
So I tried:
gem install Gosu
Which gives:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.
But rbenv global gives:
1.9.3-p0
What is going on? Shouldn't the running Ruby be 1.9.3-p0? I tried rbenv rehash several times and I also tried rbenv init.
I also have:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
in my ~/.zshrc file.
What am I doing wrong?

Related

ERROR: While executing gem ... (Gem::FilePermissionError)

I'm trying to setup rbenv to use with fastlane. I follow the instructions here. I've installed rbenv
rbenv install 2.3.1
Then updated it so the version points to:
rbenv local 2.3.1 => 2.3.1 (set by /Users/pepe/Development/test-ios/.ruby-version)
I then try to install bundler:
gem install bundler and get the following error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
And running following gives me:
rbenv which gem
/Users/pernillau-ext/.rbenv/versions/2.3.1/bin/gem
which gem
/Users/pernillau-ext/.rbenv/shims/gem
Obviously rbenv points to one installation of gem and the system (Mac OS X 10.116) comes with preinstalled ruby and gems which is installed in /Library/Ruby/Gems/2.0.0 directory. So, what am I missing here? Why is gem command using the wrong version.
EDIT:
My bash_profile:
export ANDROID_HOME=/Users/pepe/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
export GEM_PATH=/Users/pepe/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
export PATH=$PATH:/Users/pernillau-ext/Library/Android/sdk/tools:/Users/pernillau-ext/Library/Android/sdk/platform-tools
PATH="$(perl -e 'print join(":", grep { not $seen{$_}++ } split(/:/, $ENV{PATH}))')"
eval "$(rbenv init -)"
Try mooving things in $PATH a little. Move rbenv to the front of the $PATH.
$PATH in your shell should look roughtly like (pseudocode):
{rbenv shims} : {rbenv bin} : {system paths}

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

How to get newer version of Ruby into gem environment

I've installed Ruby 2.2.2 with rbenv. However when I run
gem env
it says that I am using 2.0.0. I read on a different question to run
sudo gem install -n /usr/local/bin --no-ri --no-rdoc bundler
rbenv rehash
bundle --path=vendor/bundle
However, when running the last line, I receive the error:
Could not locate Gemfile or .bundle/ directory
How do I get the system to use Ruby 2.2.2?
EDIT:
I printed out the contents of my .bash_profile and it had the following two lines:
export PATH
export PATH="$HOME/.rbenv/bin:$PATH"
Is it bad that there is a blank export PATH? If so, how do I remove it?
If you have Ruby 2.2.2 installed already, you can use renv global
rbenv global 2.2.2
Check out the documentation here.
It turns out RVM was still present in the system. All I had to do was run:
rvmsudo rvm implode

rbenv: gem commands are not found on Linux Mint

I'm on Linux Mint 17.2.
I recently removed ruby with apt-get purge ruby.
I then installed rbenv and then did rbenv install 2.3.0 so now, ~/.rbenv/versions/2.3.0/bin/ruby exists.
But now, I can't do gem install rubocop. I get this:
$ gem install rubocop
rbenv: gem: command not found
The `gem' command exists in these Ruby versions:
2.3.0
But I can do ~/.rbenv/versions/2.3.0/bin/gem install rubocop.
However, once I'm done, I can't use it:
$ rubocop --auto-correct
-bash: /usr/local/bin/rubocop: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
I also can't find out where this ruby came from:
$ dpkg -S /usr/bin/ruby1.9.1
dpkg-query: no path found matching pattern /usr/bin/ruby1.9.1
It's possible it was installed via RVM a long time ago.
Any idea how I can fix my Ruby?
try run rbenv global 2.3.0 && rbenv rehash
It looks like you haven't run the rbenv shell magic to add bin shims to your path.
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
It's recommended to add that to your .bashrc or .bash_profile so it gets executed on login.
Take a read through this - it covers rbenv and bundler but the initial setup will be what you need to look at.

rbenv and bundler: "bad interpreter: No such file or directory"

I messed up my configuration. I am running Ubuntu 14.04 and had some issues when I tried to move from a project to an other. I tried to uninstall and reinstall rbenv and then installed Ruby 2.1.7 following this guide: https://gorails.com/setup/ubuntu/14.04.
Now, when I run gem install bundler nothing happens and I can't install any gems. When I type bundler or bundler -v I see this:
/usr/local/bin/bundler: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
I spent many hours trying to solve this but I really don't know what to do.
Find the bundle executable (in a non project directory - default system ruby) and delete it:
which bundle
rm <path_obtained_above>
Now go to your project directory, or switch to your ruby version and install bundler:
gem install bundler
Then execute rbenv rehash
and now try executing bundle install and it should work. You will need to do this once for each ruby version installed.
The fact that gem is being executed by your /usr/local/bin means that rbenv isn't in your $PATH correctly.
Step 1:
Please delete any references you have of rbenv in the following areas:
~/.profile
~/.bashrc
~/.bash_profile
~/.gemrc
Step 2:
Reinstall rbenv using these instructions. It won't override, it will simply update changes to your ~/.bash_profile. Once reinstalled close your terminal and reopen. Everything should work correctly at that time.
Step 3:
Verify that everything was installed correctly by executing cat ~/.bash_profile. You should see the following. If you do, you're good to go.
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Many cudos to #theTinMan for recently helping me sort through my rbenv installation.

Resources