Yesterday I updated my Ruby version to 2.6.5 with rbenv, but today I had a problem when I wanted to update Rails to 6.0.2.1.
It didn't work well.
This is what I have:
echo $PATH
/usr/local/opt/ruby/bin:./bin:./node_modules/.bin:/Users/paulinedussart/.rbenv/shims:/Users/paulinedussart/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/Users/paulinedussart/.rvm/bin
ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
which ruby
/usr/local/opt/ruby/bin/ruby
I did:
gem install rails
I got:
Successfully installed rails-6.0.2.1
Parsing documentation for rails-6.0.2.1
Done installing documentation for rails after 0 seconds
1 gem installed
then rbenv rehash.
When I ran which rails or which -a rails I got:
/usr/bin/rails
To check if everything was ok I ran rails --version but the result was:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
but I did not do that.
Somewhere I saw this instruction
ls `rbenv prefix`/bin
to check if Rails was there but it doesn't appear:
bundle bundler erb gem irb rake rdoc ri ruby
Finally, when I run gem list rails I get:
*** LOCAL GEMS ***
rails (6.0.2.1)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.3.0)
sprockets-rails (3.2.1)
I obviously closed the terminal at a different step of the config but without success.
I'm sure there is a problem with folders but I don't know how to fix this to put the gem rails in the correct one.
Does somebody have an idea?
Try this:
Switch to Ruby 2.6.5:
rbenv global 2.6.5
Install the Bundler gem:
gem install bundler
Install Rails:
gem install rails
Try using: rbenv rehash.
Also you can check "Rails is not currently installed on this system - High Sierra #1106".
I had the same issue and I refered to this issue and found we don't need:
export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
You just need:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
if you install it via Homebrew.
This is what I have done:
gem uninstall rails
gem uninstall railties
gem install rails 3.2
And terminal shows this code:
Done installing documentation for rails, railties after 1189 seconds
ERROR: Could not find a valid gem '3.2' (>= 0) in any repository
2 gems installed
weare138#mycomp:~$ rails -v
Rails 4.1.5
How to fix it?
You are missing the -v flag so rubygems is thinking that 3.2 is the name of a different gem and you are installing the current version (4.1.5). Instead try:
gem install rails -v 3.2.19
You should not need to remove up-to-date versions as you can specify the older rails version when starting a project with:
rails _3.2.19_ new myapp
If you are using RVM, create a new gemset
rvm gemset create <name>
Then you can switch to that gemset using
rvm use 1.9.3#<name> #assuming your ruby version is 1.9.3
That gives a clean gemset you can install Rails 3.2 to. Maintain multiple gemsets and switch between them
Here are my local gems :
$ gem list
*** LOCAL GEMS ***
actionmailer (4.0.0, 3.2.14)
actionpack (4.0.0, 3.2.14)
activemodel (4.0.0, 3.2.14)
activerecord (4.0.0, 3.2.14)
activerecord-deprecated_finders (1.0.3)
activeresource (3.2.14)
activesupport (4.0.0, 3.2.14)
arel (4.0.0, 3.0.2)
atomic (1.1.13)
builder (3.1.4, 3.0.4)
bundler (1.3.5)
bundler-unload (1.0.1)
erubis (2.7.0)
hike (1.2.3)
i18n (0.6.5)
journey (1.0.4)
json (1.8.0)
mail (2.5.4)
mime-types (1.24)
minitest (4.7.5)
multi_json (1.7.9)
polyglot (0.3.3)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.14)
railties (4.0.0, 3.2.14)
rake (10.1.0)
rdoc (3.12.2)
rubygems-bundler (1.2.2)
rubygems-update (2.0.7)
rvm (1.11.3.8)
sprockets (2.10.0, 2.2.2)
sprockets-rails (2.0.0)
thor (0.18.1)
thread_safe (0.1.2)
tilt (1.4.1)
treetop (1.4.15)
tzinfo (0.3.37)
But when I type rails -v I get this :
$ rails -v
Rails 4.0.0
$ which rails
/Users/polonium/.rvm/rubies/ruby-2.0.0-p247/bin/rails
How can I specify rvm to use rails version 3.2.14 ?
Thanks in advance
You can create a new rails app with a particular rails version, like this:
rails _3.2.14_ new myApp
How can I specify rvm to use rails version 3.2.14 ?
rvm has nothing to do with rails. rvm is used to manage multiple ruby installations. And each of your ruby installations can be associated with multiple gemsets. For instance, say you have ruby 1.9.3 installed and you created two gemsets for ruby 1.9.3: gemsetA and gemsetB. If you tell rvm to use ruby 1.9.3 with gemsetA, that means:
Your ruby programs will be executed by ruby 1.9.3.
Your ruby programs can require any gem in gemsetA (which then allows your program to use the methods (or classes) defined in gemsetA), but any gems in gemsetB cannot be seen by your ruby program.
Here's a concrete example:
~$ rvm list
rvm rubies
ruby-1.8.7-p370 [ i686 ]
* ruby-1.9.3-p194 [ x86_64 ]
=> ruby-2.0.0-p0 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
# => - current
# =* - current && default
# * - default
~$ rvm use 1.9.3-p194
Using /Users/7stud/.rvm/gems/ruby-1.9.3-p194
.
~$ rvm gemset list (This lists only the gemsets for the current ruby version)
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
programming
rails3tutorial
rails4
~$ rvm gemset use programming
Using ruby-1.9.3-p194 with gemset programming
After I do that, my ruby programs will be executed by ruby 1.9.3 and any gems in the programming gemset can be required into my ruby program. You can use a shortcut to perform both those commands in one step:
rvm use ruby 1.9.3-p194#programming
You just combine the ruby version and the gemset with an '#' between them.
But when I type rails -v I get this :
$ rails -v
Rails 4.0.0
That's because the current gemset contains the gem for rails 4.0.0. If you want to see $ rails -v output Rails 3.2.14, then you need to tell rvm to switch to a gemset that contains the rails 3.2.14 gem.
However, you can make rvm automatically switch to the proper rails version and gemset for your rails project. In your Gemfile, add a comment after the ruby version:
ruby '2.0.0'
#ruby-gemset=railstutorial4_gems
Then whenever you switch to the directory containing your rails project, rvm will automatically switch the current ruby to ruby 2.0.0 and the current gemset to railstutorial4_gems. If you change directories out of your rails app, rvm will change the current ruby and the current gemset back to what they were.
I'm just a rails beginner, but here are the steps I use to create a new project, which are straight out of the railstutorial book (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book)
1)
.../rails_projects$ rvm use <ruby version here>#<new gemset name here> --create
e.g.
.../rails_projects$ rvm use ruby-1.9.3-p194#myapp_gemset --create
2)
.../rails_projects$ gem install rails --version 3.2.14
Because the current gemset is the myapp gemset, that command installs the rails 3.2.14 gem into the myapp gemset.
3)
.../rails_projects$ rails new myapp
.../rails_projects$ cd myapp
The current gemset is still myapp_gemset.
4)
.../rails_projects/myapp$ rails -v
Rails 3.2.14
In case anyone was wondering what the heck the following two gemsets are all about:
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
rvm creates those two gemsets for every ruby version you install. After you install a ruby version, if you don't create a gemset yourself for that ruby version, and you install a gem, then the gem goes into the (default) gemset. And, if you want all your gemsets to contain a certain gem, you can switch to the global gemset and install the gem there.
Update: -------
To maintain compatibility with other ruby version managers, you can specify the ruby version and gemset name for your project in a different file rather than in the Gemfile:
$ cd ~/rails_projects/myapp
~/rails_projects/myapp$ echo 2.0.0 > .ruby-version
~/rails_projects/myapp$ echo myapp_gemset > .ruby-gemset
You'll still get the same automatic ruby version and gemset switching when you cd into your project's directory. See the rvm docs here.
the path you found /Users/polonium/.rvm/rubies/ruby-2.0.0-p247/bin/rails is not proper path you would found in standard rvm installation while doing proper use of rvm, what you would see should be: /Users/polonium/.rvm/gems/ruby-2.0.0-p247/bin/rails
to get it working properly try this flow:
rvm use 2.0.0
rvm gemset empty
rvm use #rails3 --create
gem install rails -v "~>3.2"
rvm use #rails4 --create
gem install rails -v "~>4"
this way now you can switch between this two rails installations with:
rvm use 2.0.0#rails3
rails -v # rails 3.2...
rvm use 2.0.0#rails4
rails -v # rails 4.0...
you should do: gem install 'rails' -v '3.2.13'
You should use a clean gemset, if you are using rvm, you can try:
rvm gemset create
rvm gemset use
Now you have a clean gemset, it's time to install rails,
gem install rails -v '3.2.13'
and then create a rails app,
rails new app_name
"railties (4.0.0," is the problem you have. I guess it was installed by mistake?
Uninstall that version using, gem uninstall railties, and then picking the option with 4.0.0.
Now the command "rails -v" will return your expected version which is "3.2.14"
Make sure to check the global gemset by first making sure you are in the ruby version you intend to use
$ruby -v
Then switch to the global gemset (the global gemset applys to all of the gemsets so be sure to keep it clean and universal...or global, hence the name)
$rvm gemset use global
After that check the gem list for gems that can affect it like the "railties" gem that Harsha mentioned by typing
$gem list
Sometimes the global gemset can be populated by an accidental gem that will affect all other gemsets. If you find a misplaced gem you can uninstall it simply with
$gem uninstall examplegem
or for a specific version of that gem pass in the -v with the version in quotes
$gem uninstall examplegem -v"3.2.1"
And read 7stud's comment on creating and using RVM for changing between different gemsets.
You could add the version of Rails you want, with:
$ gem install rails --version 3.2.14
And then create an app with that version:
$ rails _3.2.14_ new myapp
Finally, you can check it out the content of the "Gemfile" to corroborate:
...
gem 'rails', '3.2.14'
...
I try to install skylinecms but I have a problem with installing the gem.
The gem factory_girl asked me to use version> = 1.9.2 of Ruby
atmoner#atmoner:~/base_ror$ sudo gem install skylinecms
ERROR: Error installing skylinecms:
factory_girl requires Ruby version >= 1.9.2.
ruby -v
atmoner#atmoner:~/base_ror$ ruby -v
ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux]
I have tried to change ruby version to 1.9.2
atmoner#atmoner:~/base_ror$ rvm use 1.9.2
Using /home/atmoner/.rvm/gems/ruby-1.9.2-p320
But still same problem
atmoner#atmoner:~/base_ror$ sudo gem install skylinecms
ERROR: Error installing skylinecms:
factory_girl requires Ruby version >= 1.9.2.
what's the source of this problem?
you have an idea?
You shouldn't use sudo with rvm, as it creates a new subshell with a completely new environment. See more about sudo and rvm here: RVM and 'sudo'
Most likely your system ruby version is 1.8.7, and that is what is getting invoked when you run sudo gem install skylinecms. You can verify that with the following commands:
rvm use system
ruby -v
Try installing the skylinecms gem without sudo.
Best to use per-project gemsets as suggested in rvm best practices
I installed RoR on ubuntu 10, using all kinds so method i could find on internet, either "sudo apt-get" or "sudo gem install", by running 'gem list', i can see they are all the latest version:
*** LOCAL GEMS ***
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
fastthread (1.0.7)
mysql (2.8.1)
passenger (2.2.15)
rack (1.1.0)
rails (2.3.8)
rake (0.8.7)
rubygems-update (1.3.7)
but when i created a ror application by running 'rails samplecode', then run 'script/about', it always showed:
About your application's environment
Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.3.5
Rails version 2.2.3
Active Record version 2.2.3
Action Pack version 2.2.3
Active Resource version 2.2.3
Action Mailer version 2.2.3
Active Support version 2.2.3
Edge Rails revision unknown
Application root /home/kc/Projects/samplecode
Environment development
Database adapter mysql
why these 2 settings are different? how can i force the application to use the local gems (latest version)? Thanks.
Ubuntu (aptitude/apt-get) installs gems in /var/lib/gems/1.8. When you run gem install manually, you're likely installing them in /usr/lib/ruby/gems/1.8.
Run "gem env" and look at what the gem path(s) is/are.
If you set the GEM_HOME environment variable (GEM_HOME=/usr/lib/ruby/gems/1.8), you can have you application look there.
Alternately, you can install the gems you want (including rails) in your application's vendor directory by putting config.gem lines in environment.rb and running rake gems:unpack:dependencies.
Uninstall the apt-get version of Rails:
sudo apt-get remove rails
And then install Rails again using gem:
sudo gem install rails