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
Related
I'm trying to install Ruby on Rails on MacOS Mojave. Here's what I have so far:
ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
rails -v
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.
which rails
usr/bin/rails
I've done some research on the issue and it looks like because I used sudo when I originally ran gem install rails, the rails executable got put in a location where it doesn't have access to the right libraries.
How do I fix this or remove the rails executable to start a fresh install from scratch?
Ignore the existing Rails installation in your system Ruby. Don't bother mucking about with any changes you've made to system Ruby and its gems. Just put it in the past and move on:
Install RVM with:
\curl -sSL https://get.rvm.io | bash -s stable
Restart your shell, then install Ruby with:
rvm install 2.6.5
Don't use system Ruby.
Then install Rails (without sudo, never use sudo with Ruby installed by RVM):
gem install rails
Show messages errors:
Required ruby-2.6.1 is not installed.
To install do: 'rvm install "ruby-2.6.1"'
ruby -v
ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32]
rails -v
Rails 5.2.2
First of all, I doubt that RVM may not be updated to support this version of Ruby. As I know the following version is supported, you can version by following command and response should match.
rvm --version
1.29.7
If you have updated version then I will do the following to check if RVM has also the same version of ruby installed.
I will check the content of my project root folder's following file
cat .ruby-version
If it has mention same, as rvm is also complaining that I will run the following command on rvm to check if this ruby is really installed in RVM
rvm list
It will show a list of rubies installed and it should include 2.6.1 in the end. If you can't see this list then you probably need to install using the following command
rvm install "ruby-2.6.1"
If it is showing than can you try the following command and see what result comes
rvm use 2.6.1
If all good, then try the following command to see which ruby is being used
which ruby
response must include .rvm/rubies/ mean you are using .rvm ruby otherwise, you may using the system built in ruby.
Just wrote may help you to diagnos issue.
Are you using rbenv? If so, I'd recommend running rvm implode as described here.
if you are using rbenv
see if you have it available in your list :
rbenv install --list | grep 2.6.1
if not, fetch it
cd ~/.rbenv/plugins/ruby-build && git pull && cd -
now if you try again
rbenv install -l | grep 2.6.1
so just run the installation command:
rbenv install 2.6.1
Downloading ruby-2.6.1.tar.bz2... 08:36:17
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.1.tar.bz2
Installing ruby-2.6.1...
Installed ruby-2.6.1 to ~/.rbenv/versions/2.6.1
now you can use it for global or local projects. if local :
rbenv local 2.6.1
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
I'm getting the next error installing RoR
How can I set the correct Ruby Version?
#####:path$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
#####:path$ sudo gem install rails
ERROR: Error installing rails:
activesupport requires Ruby version >= 1.9.3.
#####:path$
You shouldn't have to use sudo with gem install .... That's what's causing the mismatch between Ruby versions, since root is using the default installed Ruby, whereas your own account is using RVM's installed version.
Updating the system version of Ruby depends on your operating system, and usually lags behind the very latest version of Ruby. I've been using 2.0 for my latest project I launched last month. I doubt big OS vendors like Ubuntu or Apple are providing that version in their latest distribution. It's best that you manage your own Rubies whenever possible.
To install 1.9.3 you can run:
$ rvm install 1.9.3
then later
$ rvm use 1.9.3
You have :
###:path$ ruby -v
.....
###:path$ sudo gem install rails
...you said in your comment that :
$ sudo ruby -v
...gives you
ruby 1.8.7
To resolve this problem you shouldn't use sudo, as it tries to install using root session with 1.8.7 ruby version which is not supported.
To install rails just type the following without sudo:
$ gem install rails
...it should works as you've a supported ruby version (ruby 2.0.0p247)
You can check Install Ruby on Rails ยท Ubuntu Linux instructions (Which I found useful) if you've more troubles.
$ sudo gem install rails
Successfully installed rails-3.1.1
1 gem installed
Installing ri documentation for rails-3.1.1...
Installing RDoc documentation for rails-3.1.1...
This did not properly work, as when I run rails, I get
The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails
And doing ruby --version gives
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
and doing which rails returns nothing. Anyone have any ideas about how I would go about installing the latest version of Rails? I've tries using the apt-get method, but I got Rails 2, however I need Rails 3 for my purposes.
I've had the similar problem with my Ubuntu installation.
Solved it following to steps:
Make sure rubygems is installed
created the following symlink:
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem