I want to use Rails with Ruby 2.1.0, but it's using Ruby 1.9.3 (the system's version).
I'm using rbenv to manage my Ruby versions. My steps were something along the lines of:
$ rbenv install 2.1.0
$ rbenv global 2.1.0
$ sudo gem install rails -v 4.0.2
$ rbenv rehash
$ rbenv versions
system
* 2.1.0 (set by /home/dennis/.rbenv/version)
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
$ rails new app && cd app
$ rails server
Rails is using is Ruby 1.9.3 (x86_64-linux), according to localhost:3000/rails/info/properties. A log message from rails server gives: INFO ruby 1.9.3 (2012-04-20) [x86_64-linux].
I think Rails is using the system version of Ruby because the versions match.
$ rbenv local system
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rbenv local --unset # Unset local Ruby version, go back to 2.1.0
Some things I've tried with no luck:
setting the local and shell versions of Ruby to 2.1.0 with rbenv
rehash rbenv shims (rbenv says to do this after installing executables)
made new Rails projects after switching to 2.1.0 just in case I made the projects while using 1.9.3
putting 2.1.0 in a .ruby-version file in the root of my project (suggested by #Agis)
restarting terminal session and starting a login bash shell (suggested by #Russel)
specifying the desired Ruby version in the project's Gemfile (suggested by #rlecaro2)
FWIW, I'm using Ubuntu 13.10 with the fish shell.
Sounds silly, but did you restart terminal session?
Otherwise try and type
/bin/bash --login
You didn't tell how you installed rbenv, but I think it is per-user installation (which is default). In this case you should install gems without using sudo. When you did sudo gem install rails, it was installed in system ruby, not rbenv's selected one.
Solution - install rails without sudo:
rbenv global 2.1.0
gem install rails
rbenv rehash
Try creating a .ruby-version file in the root of your project with the following contents:
2.1.0
Related
I am trying to install Ruby on rails on a Mac Mojave:
$ brew install ruby
Warning: ruby 2.7.1 is already installed and up-to-date
To reinstall 2.7.1, run `brew reinstall ruby`
This shows me that I am running Ruby 2.7.1.
But when I check the version I get:
$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
This tells me I am using Ruby 2.3.7.
I don't understand.
To run Rails I need >= 2.4.4 apparently:
$ sudo gem install rails
.....................
ERROR: Error installing rails:
zeitwerk requires Ruby version >= 2.4.4.
and
$ which ruby
/usr/local/opt/ruby/bin/ruby
So until I get ruby version to at least 2.4.4 I can't run rails.
Update
Install RVM on MAC as follows
$ brew install gpg
$ curl -L https://get.rvm.io | bash -s stable --autolibs=enabled --ruby
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
Got these instructions from:
https://null-byte.wonderhowto.com/how-to/mac-for-hackers-install-rvm-maintain-ruby-environments-macos-0174401/
But then I install Rails:
$ sudo gem install rails
Successfully installed rails-6.0.2.2
Parsing documentation for rails-6.0.2.2
Done installing documentation for rails after 0 seconds
1 gem installed
and so I tried to crate a Rails project:
$ rails new blah
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.
What is going on there? I seem to have successfully installed Rails but cannot create a Rails project.
The output from this command brew install ruby is not telling you that you're running ruby 2.7.1. That just says you already have ruby 2.7.1 installed for brew. But you could have other ruby versions installed in other ways. When you do
ruby -v
ruby executable is looked for in paths listed inside your environment variable PATH, in order. You can see those paths with
echo $PATH
So, managing different versions of ruby is hard and version managers exist for this reason. I suggest you to install rvm
I have recently moved from RVM to Rbenv and when attempting to execute rails I am getting an error like the one below
Pauls-Air:~ $ rails
rbenv: rails: command not found
The `rails' command exists in these Ruby versions:
2.1.2
After installing a gem via the command line in a ruby version you have to execute rbenv rehash as described in the docs here and here
For example:
$ rbenv install 2.2.0
$ gem install bundler
$ rbenv rehash
$ gem install rails
$ rbenv rehash
You need to install Rails for each Ruby version within rbenv. Try running rbenv version, I might expect that 2.1.2 is not the ruby version in use for the current project (local version) or maybe your global version.
I ran into the same issue, but none of these other solutions (or any of the others I found elsewhere) worked. I was about to go back to RVM, so I decided to get rid of rbenv completely and it paved the way to the solution.
Try the following - it worked for me:
uninstalling rbenv, remove all references rbenv in your bash profile, and remove the remaining rbenv file folder and its contents.
Reinstall rbenv with homebrew.
Add it back to your bash profile:
export PATH="$HOME/.rbenv/bin:/usr/local/bin:$PATH"
eval "$(rbenv init -)"
Restart the shell:
exec $SHELL -l
Check the path:
echo $PATH
Install Rails:
gem install rails
rbenv rehash
Note: I consulted this for part of this answer: https://www.codementor.io/tips/3732499178/solution-for-rbenv-rails-is-not-currently-installed-on-this-system-to-get-the-latest-version-simply-type
Try to set up your environment with 2.1.2 version running this command line in your terminal:
$ rbenv shell 2.1.2
It works to me
Ensure that the .ruby-version file in your project's directory contains the same ruby version as the one you installed with rbenv.
For me, I set up my environment with the listed "The `rails' command exists in these Ruby versions".
$ rbenv shell 2.1.2
$ rails -v
It works.
Like for example if you want to install Ruby 2.5.3 with Rails 6
follow this way:-rbenv global 2.5.3
$ gem update --system
$ rbenv install 2.5.3
$ rbenv global 2.5.3
$ gem install rails -v 6.0.2.2
$ ruby -v
$ rails -v
The problem is that your global ruby version doesn't match your installed somewhere locally version which is 2.1.2. Try executing anywhere in bash shell:
rbenv global 2.1.2
That way rails will be found by rbenv in your $HOME directory and anywhere else.
rbenv global
Sets the global version of Ruby to be used in all shells by writing
the version name to the ~/.rbenv/version file. This version can be
overridden by an application-specific .ruby-version file, or by
setting the RBENV_VERSION environment variable.
I'm getting started with Rails development and have a dev environment setup on OS X Yosemite, but the Ruby and Rails versions are a bit wonky. I used homebrew to install Rails, and everything seems to have gone well. Although which rails claims it's located in "~/.rbenv/shims/rails", and not /usr/local/bin where homebrew is supposed to place its apps. There's also /usr/bin/rails which when run yields:
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.
rails --version returns Rails 4.2.0.
I can create a rails app fine, but when I run rails server the ruby version is ruby 2.1.5 (2014-11-13) [x86_64-darwin14.0].
I followed these instructions (mac-dev-env.patrickbougie.com/ruby-22/) to compile ruby 2.2.0 and ruby --version returns "ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]". which ruby returns "/usr/local/rbenv/shims/ruby".
Relevant lines in .bash_profile from brew install of Rails and compiled ruby 2.2.0 are:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
export PATH=/usr/local/openssl/bin:$PATH export
MANPATH=/usr/local/openssl/ssl/man:$MANPATH export
PATH=/usr/local/rbenv/bin:$PATH export RBENV_ROOT=/usr/local/rbenv
eval "$(rbenv init -)"
How do I get the 2.2.0 version of Ruby to run with Rails? Everything I have read thus far suggests rvm (rvm.io). However, I get homebrew errors when I try to install Ruby that way.
From: http://railsapps.github.io/installrubyonrails-mac.html, section: "If You Already Have RVM Installed"
$ rvm get stable --autolibs=enable
$ rvm install ruby
$ rvm --default use ruby-2.2.0
rvm install ruby throws the homebrew error.
rvm seems unnecessary considering Ruby 2.2.0 is compiled on my machine already.
I appreciate any help, thank you!
I'm installing Ruby using MacPorts.
After using the following command:
sudo port install rb-rubygem
I got the following error:
Error: Port rb-rubygem not found
What should I be doing?
This post is old but I'll add this here. If you want to use mac ports you can add ruby by using sudo port install ruby and then sudo port install rb-rubygems (notice you missed the 's' in rubygem*s* in your original post). You can always check what repositories are available in mac ports by typing port list. Hope this helps.
Ruby is installed by default in every mac. However, it's ruby 1.8, which is very old and shouldn't be used in any of your projects.
Take a look at rvm.
It will allow you to install several versions of ruby in the same system.
So, for example, you can do the following :
rvm use 1.9.3
ruby -v #=> ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin12.2.0]
rvm use 2.0.0
ruby -v #=> ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]
Using rvm, you can install any new version of ruby using the following :
rvm install 2.0.0-p0 #=> This will install Ruby 2.0.0
rvm install jruby #=> This will install jruby
And so on
Odd problem, trying to figure out what is going on here with my fresh install.
I installed Ruby 1.9.3 using homebrew. I installed Rails 3.2.0 using ruby gems. I then created a test application with rails new test_app to make sure everything looked okay in the test environment. Somehow, the rails environment is using 1.8.7 instead of 1.9.3.
When doing a ruby -v, I get this:
overcast:test_app joe$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
But when running rails s I get this:
overcast:test_app joe$ rails s
=> Booting WEBrick
=> Rails 3.2.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-01-21 23:21:35] INFO WEBrick 1.3.1
[2012-01-21 23:21:35] INFO ruby 1.8.7 (2010-01-10) [universal-darwin11.0]
And, obviously, when looking at the rails environment webpage at localhost:3000 I am showing 1.8.7 instead of 1.9.3. I've edited /etc/paths to have /usr/local/bin at the top based on some answers I've found here, but it doesn't seem to make a difference.
Any help would be greatly appreciated!
Addendum: The same situation happens when installing and attempting to use Ruby through RVM.
If you are running mac os x you have ruby 1.8 preinstalled. Use RVM or rbenv if you want to have more than one ruby version installed.
Homebrew not so bad :)
You may use rbenv. It is ruby version manager.
My success story for MAC OS X 10.8.2 is:
install Homebrew
change PATH in /etc/paths (/usr/local/bin need to be first)
install rbenv and ruby-build (it is plugin for rbenv) using homebrew
create ~/.profile with content:
export RBENV_ROOT=/usr/local/opt/rbenv
if which rbenv > /dev/null; then
eval "$(rbenv init -)"
fi
install last stable ruby version using rbenv install 1.9.3-p374
change default ruby version using rbenv global 1.9.3-p374
update gem using gem update --system (optional)
install rails gem install rails
...
Profit :)
bundle exec rails server
Should work just fine. It also worked for me to close the terminal and open a new one.
if you have multiple versions of ruby, I recommend you use RVM
Install it https://rvm.io/rvm/install
Use: https://github.com/wayneeseguin/rvm#usage
To view all versions of ruby use "rvm list"
and set default version "rvm --default version"
sudo update-alternatives --config gem
and select your verison!