Why do my gems install into the wrong folder? - ruby

I installed Ruby and Rails via RVM, but using "gem install something", the console tries to install into /Library/Ruby/Gems/1.8 directory.
Do I still need this Ruby dir?

You are still using the default Ruby. You need to activate RVM for your shell session. See item 2 at the below:
http://beginrescueend.com/rvm/install/
(and no I wouldn't delete the original Ruby dir)

You have to direct your shell to use RVM and the Ruby version. You can do so by issuing the following command:
rvm use *ruby version (example: 1.8.7)*
Or, if you have created a gemset for particular project:
rvm use *ruby version (example: 1.8.7)*#*my_gem_set*

Related

How to set specific Ruby version for projects(no rvm and rbenv)

I worked on some project when in some moment I have to change Ruby version for some other project. Now when I want to go back to first project, I'm getting some errors because of Ruby version. The question is how to change Ruby version(currently I'm on RVM-installed Ruby 2.5.1) and want to back to Ruby 2.4.5 but it wasn't installed via Rvm or Rbenv, just clean installation.
I know how to change Ruby version via Rvm, but how to change to version which is not installed with any addition (Rvm or Rbenv)
Even though this doesn't answer your question directly, I would recommend against using both RVM Ruby and system Ruby together. RVM was not designed to work that way and every issue arising from this kind of installation would be quite difficult to debug, particularly if you are a beginner.
So the easiest way to go would be to remove the system Ruby completely and create a 2nd RVM gemset for your other project. (This is how RVM is intended to be used, actually.)
See doc: https://rvm.io/gemsets/creating
https://rvm.io/gemsets/basics
If you have more then one projects with different ruby versions then we need to use rvm gemsets to avoid conflicts.
Steps to be followed:
rvm gemset create sriharsh
rvm use 2.2.1#sriharsh --create
rvm gemset list (to check list of gemsets)
rvm list (list of rvm rubbies)
However, if you are using Bundler then you don't need to use RVM Gemsets. Prepending any command with bundle exec will execute it in the context of the project's Gemfile.
For ex:
bundle exec rails s

How to change ruby version on linux

I installed rvm on my Linux machine and download simple project from github. I tried to run rails s, but got a error with ruby version:
I executed next commands:
rvm install ruby-2.3.0
rvm use ruby-2.3.0
rvm use ruby-2.3.0 --default
When I opened the project and ran rails s, I got this error
https://i.imgur.com/Dwvp8WF.png
Update
My Gemfile has ruby 2.3.0
Can't run bundle install because of this error https://imgur.com/a/UMcirdt
w
which rails, which ruby: https://imgur.com/a/vycG8wG
I haven't used rvm, but I'm using rbenv for version management.
From what I've read, it works similarly, although the commands are a little bit different.
Did command rvm use ruby-2.3.0 inside the project folder generate a file called .ruby_version?
It should list the current version of ruby used in this project
After checked the errors on your updated screenshot, I think it's better just do this:
rm -r ~/.bundle
bundle
bundle install
Maybe just
rvm reinstall all
then try again.
If permission error happens, run
rvm fix-permissions
And then do it again.

Using a particular Ruby version on a project

I am trying to use a specific version of ruby on a particular project. I looked into the RVM and rbenv packages, but had little success with any of them.
These are the steps I took:
create project directory and navigate to it;
run rbenv install 2.3.1; after navigating to ~/.rbenv/versions I can see a "2.3.1" in there;
running "rbenv local" also echos 2.3.1;
My Gemfile is as follows:
ruby '2.3.1'
source 'https://rubygems.org/' do
gem 'test-kitchen'
gem 'kitchen-terraform'
end
However, when I run bundle install i get the following error:
Your Ruby version is 2.5.1, but your Gemfile specified 2.3.1
Its my first time working with Ruby, so I am struggling a little. I appreciate all help, and can provide more details if required.
If you store the ruby version of your project in .ruby-version and the gemset (i.e. gem list workspace) in .ruby-gemset of your project (which I recommend doing if the specific version is important to you), rvm should pick this up when you cd into your project directory. Sometimes it doesn't however depending on your setup or installation, in which case you can choose them explicitly with:
rvm use `cat .ruby-version`
rvm gemset use `cat .ruby-gemset
which I add to any installation scripts for example. You may need to run gem install bundler before running bundle install the first time you use the new gemset.
Set your default rbenv version like this:
$ rbenv shell jruby-1.7.1
See in: https://github.com/rbenv/rbenv#rbenv-shell

How to use a certain ruby version?

I try to run a script on a LFS Batchsystem. The cluster offers an older version of ruby, so I had to install my gems and rvm locally on my account. Is there a way to run my local installed ruby version on a batch system? My script works fine on my account but not on LFS because mechanize depends on a newer ruby version.
Make sure you have rvm then
rvm use 1.9.3
or to set the default:
rvm use --default 1.9.3
And obviously, replace 1.9.3 with the version you want to use
Create .rvmrc file in your working directory in that you would mention which version of ruby you are going to you like:
rvm use 1.9.3#gemsetname --create
Now you can install all gems for this particular gemset.
I solved my problem with directly using the binary version and to define my local gem folder:
GEM_HOME=/home/my_name/.rvm/gems/ruby-2.0.0-p195/gems
/home/my_name/.rvm/bin/ruby-2.0.0-p195 my_script.rb
The other solutions do not work, because rvm is not available on the cluster.

How to update system Ruby to 1.9.2 on Mac?

I saw an answer saying I should use RVM. But I don't know how even after:
$ rvm system
$ rvm current
system
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
The title of the question, "How to update system Ruby to 1.9.2 on Mac" makes me wonder if you are trying to upgrade Apple's installation of Ruby 1.8.7 to 1.9.2. If that is true, STOP and do NOT try that. The Ruby installed by Apple is for their use, and apps installed by Apple use it.
find /usr -name '*.rb'
will list the reasons why.
RVM and other apps allow you to install Ruby safely, so unless you have very good knowledge of how Unix and the Mac work I strongly recommend you stick to them.
A very common problem we see is that the installation wasn't completed. Read the "Installation" section in the RVM installation page to double-check you've completed everything.
To install Ruby 1.9.2 do:
rvm notes
and read and install the needed dependencies. Then do:
rvm install 1.9.2
rvm use 1.9.2 --default
will tell RVM to always use 1.9.2 as a default. You can switch to the system version installed by Apple using:
rvm use system
and switch back using
rvm default
If you don't want an RVM-based solution:
Download and install Apple's Xcode developer tools so you get GCC et al, the ability to build your own software. (This is 4.25GB, but you only need to download it once.)
Download and extract the Ruby Source Code. (10.6MB)
Open a Terminal window and change into the directory of the source code.
Run the command ./configure && make; get a cup of tea while you wait
Run the command sudo make install to install this Ruby; you'll need to supply your administrator password
Modify your PATH environment variable to put /usr/local/bin in front of /usr/bin (so that your new Ruby is found before the system Ruby). You can do this by creating or editing a .profile file in your home directory to have the line:
export PATH="/usr/local/bin::$PATH"
If you're running TextMate, you'll also want to go to TextMate ▸ Preferences ▸ Advanced ▸ Shell Variables
and add or edit a PATH variable like this:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
After this, rvm use system will use your 1.9.2p180 (the current version as of this post) install.
I'm assuming you're not sure how to install a new version of ruby with RVM - try:
rvm install 1.9.2
To then make it the default version to use:
rvm use 1.9.2 --default
Consider also: "for OS X try using RailsInstaller for OS X or try the official RVM GUI JewelryBox" -- Quoted from from the 4rd or 5th screen the RVM install page found here http://rvm.io/rvm/install
Whatever you do do not touch or mess with the system default Ruby that ships with your Mac I did that to see what would and my system was out of whack. If you would like to use a different version of Ruby use rvm.

Resources