'sudo ruby setup.rb' won't install Gems on Vagrant box - ruby

I'm new to using Vagrant and am trying to install Gems on it (Ruby is already installed). I am following the instructions here.
I've downloaded the latest version of Gems and extracted it. I have "cd'd" into that folder and have tried to run:
ruby setup.rb
But get a Permission denied error, so I try sudo:
sudo ruby setup.rb
But this gives me the error:
sudo: ruby: command not found
Would anyone know what's going on here?
Edit - more info
I checked the version of ruby and its 2.3.0p0.
If I try to check the version of Gems is says to install Ruby 1.9.1.
I don't really understand this...

sudo doesn't preserve your $PATH environment variable, so unless ruby is installed somewhere that's in root's path, it's not going to be found.
Run which ruby to find out where ruby is installed, then sudo /path/to/ruby setup.rb
Also, more importantly, that's completely unnecessary. Those instructions are old. Rubygems has been built-in to ruby for a long time now. The site you linked even says, "If you’re on Ruby 1.9.*, then you don’t have to worry about installing Rubygems; it’s built in." If you're on 2.3.0, you don't need to install Rubygems, you have it already.

I suggest to you use RMV to install Ruby and Gem versions.
Install RVM
https://rvm.io/
- gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
- \curl -sSL https://get.rvm.io | bash -s stable
- source /home/vagrant/.rvm/scripts/rvm
Install Ruby
rvm get stable --autolibs=enable
rvm install ruby-2.3.1
Use default ruby version
rvm --default use ruby-2.3.1

Related

Cannot install jekyll as it complaints: 'requires Ruby version >= 2.3.0'

I have only one ruby version installed:
$ rvm list
=* ruby-2.5.7 [ x86_64 ]
# => - current
# =* - current && default
# * - default
But any time I install jekyll or bundler I got complain of an older version.
$ sudo gem install bundler
ERROR: Error installing bundler:
bundler requires Ruby version >= 2.3.0.
Unable to find the reason.
Operating system: CentOS
When using RVM as your Ruby manager you do not (and should not) use sudo. Sudo runs everything under the root account. But RVM is installed under your own user account, and therefore sudo is not needed, and will in fact circumvent RVM if used.
So, just drop the sudo part, and if RVM is installed properly, everything should start working correctly:
gem install bundler # <- no sudo needed
I bit late, but I had the same problem and couldn't find an answer documented anywhere.
The problem is that sudo uses a different version of ruby than what rvm has set. You can see this by comparing ruby -v and sudo ruby -v.
To solve this, try rvmsudo gem install bundler. This causes sudo to use the version of ruby that rvm expects.
Read more here: https://rvm.io/integration/sudo

rvm default still not working

This is such a pain. It's happened before but still unable to figure it out.
[~]$ rvm use 2.1.5
Using /Users/snowcrash/.rvm/gems/ruby-2.1.5
[~]$ rvm get head
Downloading https://get.rvm.io
No GPG software exists to validate rvm-installer, skipping.
Downloading https://github.com/rvm/rvm/archive/master.tar.gz
Upgrading the RVM installation in /Users/snowcrash/.rvm/
RVM PATH line found in /Users/snowcrash/.mkshrc /Users/snowcrash/.profile /Users/snowcrash/.bashrc /Users/snowcrash/.zshrc.
RVM sourcing line found in /Users/snowcrash/.profile /Users/snowcrash/.bash_profile /Users/snowcrash/.zlogin.
Installing rvm gem in 1 gemsetsError running 'command gem install /Users/snowcrash/.rvm/gem-cache/rvm-1.11.3.9.gem --local --no-ri --no-rdoc',
showing last 15 lines of /Users/snowcrash/.rvm/log/1434304025_ruby-2.0.0-p195/gem.install.rvm->=1.11.3.9.log
[2015-06-14 13:47:05] command
current path: /Users/snowcrash/.rvm/src/rvm
GEM_HOME=/Users/snowcrash/.rvm/gems/ruby-2.0.0-p195#global
PATH=/Users/snowcrash/.rvm/gems/ruby-2.0.0-p195#global/bin:/Users/snowcrash/.rvm/rubies/ruby-2.0.0-p195/bin:/Users/snowcrash/.rvm/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/Users/snowcrash/Library/ec2-api-tools-1.3-24159/bin:/Users/snowcrash/bin:/Users/snowcrash/Library/android-sdk-mac_86:/Users/snowcrash/Library/android-sdk-mac_86/platform-tools:/Users/snowcrash/Library/bin:/usr/local/mysql/bin:/Library/PostgreSQL/9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/snowcrash/bin/gsutil:/usr/local/graphviz-2.14/bin
GEM_PATH=/Users/snowcrash/.rvm/gems/ruby-2.0.0-p195#global
I've checked .bash_profile files, etc but all seem to use 2.1.5. Where is 2.0.0 coming from?
Your error message states "No GPG software exists". You will need to install grpg2 first. You can do that with brew:
brew install gpg2
If you want to set the default, then you need to do
rvm --default use 2.1.5
then ruby -v should have the correct version.
Source
Run the following code
rvm use 2.1.5 --default
You should see
Using ... /ruby-2.1.5
Or you can check by typing ruby -v

installing RubyGem on CentOs 5

My ultimate goal is to install Sass.
To do this I need to install RubyGems
To do this I need to install Ruby.
I installed Ruby with yum.
I then tried to install gem with yum yum install rubygem
The response is "nothing to do" and yet when I write gem install sass I get:
gem: command not found
I decided to try to install rubygems 2.2.2 manually. After downloading it, I tried to run ruby setup.rb and in response I get:
Rubygems now requires Ruby 1.8.7 or later
But yum does not seem to be able to install anything later than 1.8.5.
So now I'm trying to do this manually.
I downloaded Ruby 1.9.2 to my home directory and followed these instructions: http://howboring.com/post/1226760251/centos-5-and-rails-3-and-ruby-1-9-2
This seems to work, but the problem is ruby1.9.2 is installed in my home directory (i.e. ~/ruby1.9.3 not system wide.
Thus in the directory where I installed ruby 1.9.2 ruby -v still gives 1.8.5 but ./ruby -v returns 1.9.2. And which ruby returns /usr/bin/ruby (I suppose I could replace this with a symlink that points to ~/ruby1.9.2/ruby but this doesn't seem like a "best practice")
So my main question is where should install ruby 1.9.2 with Root Permissions so that 1.8.5 is replaced with 1.9.2 system wide.
My corollary question is: is there any easier way to do this? (perhaps install sass without install rubygems??)
I then tried to install gem with yum yum install rubygem
You have a typo in the package name, it is actually named rubygems.
Can i suggest Wayne Seguins excellent rvm (ruby version manager). As the home page states:
"RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems".
Site has comprehensive installation instructions. I've posted a truncated Set of instructions for installing on POSIX systems below, but please refer to the projects' home page as:
"we have spent massive amounts of man hours debugging the installation process. Please use the install process(es) from this site only, as this is the only supported installation types and methods."
Install RVM (development version):
\curl -sSL https://get.rvm.io | bash
Close out your current shell or terminal session and open a new one (preferred). You may load RVM with the following command:
user$ source ~/.rvm/scripts/rvm
test the installation was successful:
user$ type rvm | head -n 1
this should output "rvm is a function"
List all known rubies:
rvm list known //this will output a large list of rubies shortened here
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p374]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p320]
[ruby-]1.9.3[-p545]
[ruby-]2.0.0-p353
[ruby-]2.0.0[-p451]
[ruby-]2.1[.1]
[ruby-]2.1-head
ruby-head
...
install the version you want:
rvm install 1.9.2
You can set a version of Ruby to use as the default for new shells. Note that this overrides the 'system' ruby:
rvm use 2.1 --default
You can also temporarily use another version of your ruby versions
rvm list known //lists system available rubies
Choose to use another ruby
rvm use 1.9.3
RVM is a great tool, well documented, and actively developed, it handles a wider scope of functionality than i can list here, and it's a tool I use everyday.
You can use rbenv to install ruby and rubygems that you need
https://gist.github.com/jpfuentes2/2002954

Why do I get "ERROR: While executing gem ... (Gem::FilePermissionError)"?

I uninstalled RVM and re-installed using a single user installation using:
\curl -L https://get.rvm.io | bash -s stable
When I do bundle, it prompts for:
Enter your password to install the bundled RubyGems to your system:
I tried using the answer in "ERROR: While executing gem … (Gem::FilePermissionError)" which did not fix it.
Then, while trying to install the gem manually, I got:
Gem::InstallError: nokogiri requires Ruby version >= 1.9.2.
An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.
then running gem install nokogiri -v '1.6.0' returned:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.
I checked all the similar posts on SO, but they didn't solve the problem. What am I missing?
I spent a lot of time fixing this issue on my MacBook. The gem update --system does not work for me.
At last, putting the following code in the ~/.zshrc file and create a new zsh session works for me.
export GEM_HOME="$HOME/.gem"
export GEM_PATH="$HOME/.gem"
after you install RVM you still need few more steps:
Load RVM to the current shell:
source ~/.rvm/scripts/rvm
Usually this would not be needed if you close and open your terminal again
Install ruby:
rvm install ruby
Use ruby:
rvm use ruby
The last step is very important as your error message mentioned system ruby not the one controlled by RVM.
Make sure to update your system rubygems with this command : sudo gem update --system --no-user-install.
bundler use it instead your local version and your bundler version could be incompatible with your system rubygems.
It works for me ;)

Rubygems on OSX missing

I feel like a compelte idiot, but I've been wrking on this all day and getting no where.
I've restarted several times trying to get a full install of Ruby on my OSX environment, RVM, Brew, Ruby: and every time I get through to the Ruby install it bottoms out on the rubygems install.
The reason I'm having to start again is that the RVM wouldn't update in Jewelerybox after my first successfull install (used a packaged all-in-one RubyInstaller) so I couldn't manage my gems - a problem caused by the initial Ruby install on the system living in the /usr/local and not under my own directory. To fix this I uninstalled all my Ruby stuff and started again.
All ok until the ruby compiler started gacking on the rubygems install section when installing ruby 2.0.0. Checking out the OSX system files under usr/bin I see that rubygems isn't there either (it should be present by default on OSX). Any ideas? (note that XCode is up to date and has command line tools installed)
Last attempt was:
$ rvm get head --autolibs=3 # get the latest RVM and build required libs
$ rvm requirements # just in case, install all other required stuff
$ rvm remove 2.0.0
$ rvm install ruby-2.0.0
. . . which fires the following error:
[2013-03-19 23:21:50] /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/bin/ruby
Exception `LoadError' at /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rubygems.rb:1073 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rubygems.rb:1082 - cannot load such file -- rubygems/defaults/ruby
mkdir -p /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0
...
install -c -m 0755 /var/folders/nq/wkj89k854tl0w97n68qdn820pzk_51/T/gem.84634 /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/bin/gem
rm /var/folders/nq/wkj89k854tl0w97n68qdn820pzk_51/T/gem.84634
ERROR: While executing gem ... (NoMethodError)
undefined method `fu_stream_blksize' for #<Gem::Commands::SetupCommand:0x007ffd0e054818>
Installing RubyGems
Installing gem executable
I had the exact same error installing ruby v2 within rvm today. I was in a user account on Ubuntu who needed to use 'sudo' -- and enter my account password for sudo -- in order to install OS dependencies.
Your question mentions running rvm requirements to install dependencies. That seems to be new behavior in rvm, as of v1.19. It seemed to install a bunch of dependencies just fine. But then installing ruby bombed.
In earlier rvm versions, typing rvm requirements would just list the dependencies for rvm and for ruby, as in Archonic's answer.
I typed rvm implode and then started over with:
\curl -L https://get.rvm.io | bash -s 1.18.21
source /home/deploy/.rvm/scripts/rvm
rvm requirements
At that point I could install the libraries/tools that rvm said I needed for rvm and ruby, and then rvm install ruby-2.0.0-p0 succeeded.
I believe the issue is where RVM places your dependencies - global vs your user folder. From a book called "Agile development with rails":
First, you’ll need to make sure you have Xcode 3 or later installed...
$ xcodebuild -version
If you have Xcode version 3 installed, you’ll need to install the Git version control system separately. Verify your installation by running the following command:
$ git --version
Next, install RVM itself:
$ curl -L https://get.rvm.io | bash -s stable
Exit your command window or Terminal application and open a new one. This causes your .bash_login to be reloaded. Execute the following command, which provides additional installation instructions tailored to your specific operating system:
$ rvm requirements
Look for the line that tells you how to install the necessary OS dependencies for Ruby (MRI). Once you complete those instructions, you can proceed to install the Ruby interpreter itself:
$ rvm install 2.0.0
The preceding step will take a while as it downloads, configures, and compiles the necessary executables. Once it completes, use that environment, and install rails:
$ rvm use 2.0.0
$ gem install rails --version 4.0.0.beta1 --no-ri --no-rdoc
With the exception of the rvm use statement, each of the above instructions need only be done once. The rvm use statement needs to be repeated each time you open a shell window. The use keyword is optional, so you can abbreviate this to rvm 2.0.0. You can also choose to make it the default Ruby interpreter for new terminal sessions with the following command:
$ rvm --default 2.0.0
You can verify successful installation using the following command:
$ rails -v
If you have trouble, try the suggestions listed under the Troubleshooting Your Install heading on the rvm site.
Hope that does it for you!
This worked for me:
rvm get head
rvm requirements
rvm install ruby-2.0

Resources