How to manually install rubygems? - ruby

I'm on Kali linux and I have a script that runs gem update --system. However I get the following error:
ERROR: Your RubyGems was installed trough APT, and upgrading it through RubyGems
itself is unsupported. If you really need the latest version of RubyGems (tip:
you usually don't), then you need to install RubyGems (and Ruby) manually,
maybe using tools like ruby-install, rvm, etc.
I have never touched Ruby in my life but I've done some research to try and solve the problem myself. I tried to download the rubygems .tgz file from this link here, extracted it with tar, and followed the only step there was, ruby setup.rb. I then tried gem update --system again but I got the same error. Then I decided to try and remove rubygems with apt like this: apt purge rubygems, but it said, NOTE: selecting 'ruby' instead of 'rubygems' and it did nothing. Then I tried to completely remove ruby with apt purge ruby but not only does it remove ruby, but other programs. Here's what apt says:
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
bundler* libruby2.7* metasploit-framework* rake* ruby* ruby-bundler*
ruby-dev* ruby-rubygems* ruby2.7* ruby2.7-dev*
0 upgraded, 0 newly installed, 10 to remove and 0 not upgraded.
After this operation, 423 MB disk space will be freed.
Do you want to continue? [Y/n]
I don't want to remove all versions of ruby nor do I want to remove the metasploit-framework or bundler since I might need them. To sum up, does anyone know how to manually install rubygems and get gem update --system to work?

I suggest using RVM (https://rvm.io/).
Using RVM, you can have different ruby installations, each with their own version of Ruby Gems. This is installed locally (in your home directory) and RVM manages your PATH variable so that you can switch between installations and gem sets (basically multiple local gem repositories, which is very useful for doing different projects).
I have not worked on Kali Linux, but you should be able to follow the process easily here: https://rvm.io/rvm/install
Take a few minutes to learn the RVM commands to install new Rubies and switch between them and managing gem sets. I believe it's worth it.

Related

Bundle install fails, Gem install succeeds

When trying to bundle install on a Gemfile that contained only the GitHub Pages gem and nothing else, on Ubuntu 18.04, I got error messages telling me to try installing eventmachine using gem install. That always succeeds, but bundle install still fails. How can I get bundler to see that the gem is installed?
I fixed this after many hours of struggle, by noticing that on the GitHub Pages repo there's a note that says
Important: Make sure you have Bundler > v1.14 by running gem update bundler in your terminal before following the next steps.
I have no idea why this mattered but I removed my ruby packages from Ubuntu and reinstalled them, then installed bundler with rubygems, which gave me a newer version:
sudo apt-get remove ruby
sudo apt-get install ruby ruby-dev
sudo gem install bundler
bundler --version
If anyone knows why I needed that version of bundler, or how I should have diagnosed this faster, I'd be interested to hear it. I'm not new to programming but I'm new to Ruby.
From my understanding it might be the gem you are trying to install requires a specific feature provided by bundler. If you check the change log of bundler there is some changes related to install github based gems on how to correctly read the user git settings. So I think that might be where the problem is from.

How to run bundle install as normal user

I am attempting to use bundle install. I am not a Ruby user - this is my first real foray into even running rake. I'm simply trying to user some packages from ThrowtheSwitch.org that use Rake and so on.
I initially installed ruby several days ago using:
sudo apt-get install ruby-full
This allowed me to use rake with Unity testing framework. Now I'd like to use CMock. the instructions for using CMock say to cd into the directory then
$ bundle install
$ bundle exec rake
So I install bundler using:
$ sudo apt-get install bundler
But then running the bundle install continuously asks me for my password. So I try:
$ gem install bundler
Which fails for write permissions on /var/lib/gems/1.9.1. So I try:
$ sudo gem install bundler
which installs OK so I try the bundle install again. But still get continuously asked for my password. So I try:
$ sudo bundle install
And get a warning that I should not run bundler as root:
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
How can I install this properly so that I can run it as expected?
Note: I have seen that there are several other questions on this topic, none of which I understood the answers to so let me underline that I am not a ruby (or even web stack) dev - I need this in layman's terms as much as possible.
Note also: I did see several mentions of RVM and rbenv. I'm not sure if they were incidental to those questions in particular or if one or both is required. I do not currently have either. Am about to research exactly what they are now.
Note the third: My platform is WSL (so Ubuntu, kind of).
I've been working with Ruby only a few weeks now. I'll say, I know where you are. I am not about to help much but will say, to your last question in the comments, that my understanding is that the two commands are different.
My understanding of a short answer.. One can have diff versions of Ruby they need to work with (legacy projects, etc) and not every version of Ruby can run every version of a given gem. For this reason, one can use rbenv or rvm to help manage the art of setting up a project with a particular version of ruby and then installing the needed gems.
I've been working with rvm on my mac and rbenv in linux and find them both similar enough for the simple stuff I've been doing. Installing rbenv on linux proved slightly easier. Once set up properly, sudo is no longer needed to install gems - which is preferred. I would recommend trying one of these and installing per their website instructions. Things should go smoother once set up.
Try running:
gem install bundler
bundle install
I will try to explain how the ruby ecosystem works:
Bundler is a gem - a module - that is installed on top of ruby. Gems are installed using
gem install <gem name>
I would recommend you look at installing a ruby version manager before doing anything else. the two main candidates are RVM and rbenv.
I find RVM is the simpler option for the beginner, but it eats up more space on your hard drive.
check out how to install rvm at https://rvm.io/
alternatively look at rbenv at https://github.com/rbenv/rbenv
after you have installed ruby you can test that it is installed correctly by calling ruby -v from the command line.
After that you can install bundler by calling gem install bundler
Once the gem is installed you should be able to run bundler, however if you are using rbenv you might need to run rehash first
I hope that explanation makes sense - please shout if you have questions.
If you - for some reason - stuck with a system installation of ruby,
this does the job:
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$GEM_HOME/bin:$PATH"
found it elsewhere: https://guilhermesimoes.github.io/blog/using-bundler-with-system-ruby

Installing gem-bundle for Redmine 2.1.4 with Ruby 1.9.3 (including rmagick 2.13.1) on Windows

I'm having problems installing json or rmagick gems on Windows, which I need because I am trying to install Redmine 2.1.4.
As none of the procedures worked out-of-the-box for me and have struggled with it myself for a couple of hours, I thought I'd just ask here for help.
I'm assuming you don't have Ruby installed yet. If you do, as any of other components mentioned below, probably it's the wisest to uninstall them before proceeding with installation.
This tutorial should help you avoid problems with json and rmagick gems on Windows.
First, download Redmine 2.1.4 from rubyforge as zip or from SVN or Git as described on the relevant Redmine Wiki page. rubyforge tends not to work, so you can be forced to use the latter.
Download RubyInstaller (1.9.3 at the time of this writing) and DevelopmentKit from rubyinstaller.org
Install Ruby using the downloaded installer. Use a directory without spaces in name, i.e. don't install it to Program Files. I checked the options as below
Open command line, check if Ruby path has been added to your system. ruby --version should show the version installed, 1.9.3 in my case. If you had command line opened while installing Ruby, close and reopen it to load path.
Extract DevKit to a path with no spaces. Change to DevKit's directory (might be e.g. under Ruby's installation, i.e. C:\Ruby193\DevKit). Execute the following:
ruby dk.rb init
ruby dk.rb review (should detect Ruby's installation path correctly)
ruby dk.rb install
Install bundler gem gem install bundler
Go to Redmine home directory. Execute bundle install. You will probably (if not yet fixed) get the rmagick error - don't worry yet.
Go get ImageMagick. I picked ImageMagick-6.8.0-7-Q16-windows-dll.exe. Install to a directory whose path doesn't include spaces, e.g. C:\ImageMagick. Choose to install header files as well, as below:
Add ImageMagick home to path. Close command line and reopen it. This will reload path.
Execute `gem install rmagick --platform=ruby -- --with-opt-lib=c:/ImageMagick/lib --with-opt-include=c:/ImageMagick/include
Go to Redmine home directory again. Execute bundle install again. Should work now.
Hope that helps!

Can not load any gems after upgrade

I'm trying to move from ruby 1.8 to 1.9 something.
I have tried installing the newer ruby in a number of ways - with rvm, with apt-get, etc. No matter which way I do it, once I've got /usr/bin/ruby pointing at that, no gems can be loaded ("no such file to load").
I have tried reinstalling them, both as super user and regular, and the gem install command finishes successfully, but it still doesn't find them.
I have also installed rubygems1.9.1
Can someone please tell me what's wrong. This is insanely frustrating - I have installed every gem several times in many many places and yet it doesn't find any of them. I have tried setting GEMS_DIR to no avail as well.
Remove every Ruby installation you got. Be sure there are no 'ruby' and 'gem' executables anywhere.
Install RVM and check if it went well
Install all the dependencies listed in rvm notes output.
Do rvm install 1.9.2 and start installing your gems.

ruby 1.9.2 installation and gems

I have installed Ruby 1.9.2 from source. But it seems there is some trouble recognizing the bundler gem which I have already installed.
My /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
It looks like my gems are in /usr/local/ruby/gems/1.9.1/gems/.
In my rails application when I attempt to run sudo bundle install I get an error:
sudo: bundle: command not found
Also, why do the directories say 1.9.1?
Type which ruby to see the path your system thinks ruby is in.
Did you use a --prefix=... option for configure when you set up the configuration? Normally Ruby from source wouldn't be in /usr/local/ruby/bin. The Ruby executable would be in /usr/local/bin/ruby, but that is not how you'd set up your PATH to use it, so that looks suspicious. Notice that your path already contains /usr/local/bin so if Ruby installed into the normal location for a source-installation, that path will pick it up and your final search of /usr/local/bin/ruby will be wrong and unnecessary.
If you installed the gem before you installed the new version of Ruby then the gem would be part of the previous installation, not the current one, and wouldn't be visible to it. They're separate installs.
Unless you are trying to do a system-wide install for multiple users there is no real reason to compile from source and allow it to install to /usr/local/bin. I highly recommend installing RVM, then letting it install any Ruby versions into RVM's ~/.rvm sandbox. Gems will also be installed relative to the currently enabled RVM controlled ruby, which is a really good thing.

Resources