How to point Rails to the right Ruby install - ruby-on-rails

I've been fighting with my Mac OS X 10.8 installed version of Ruby and tried to move to a .rvm install in order to keep everything up to date.
After going through all the documentation on the RVM website, here are some outcomes:
~$ which ruby
/Users/localadmin/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
~$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
~$ which rails
/usr/bin/rails
~$ rails -v
-bash: /usr/bin/rails: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
I'm not exactly sure what's causing this. I'm expecting that Rails is trying to use the system Ruby version, which isn't what I set as default in RVM.
I've read that it could be a .gemrc problem, but I can't seem to find a .gemrc file in my home directory. I can't seem to find any references to rails in my .rvm directory, so I'm thinking maybe when I did "gem install rails", "gem" was actually the one affiliated with my system Ruby.

Sorry to answer my own question, and I'd be happy if it gets deleted, but the solution was fairly annoying.
I had been installing rails with:
sudo gem install rails
I guess this took me out of the userspace in which my RVM installation sat
gem install rails
installed rails properly and now I get "Rails 3.2.9" as the outcome to rails -v
Could anyone shine any light on why this happened?

When using RVM, you pretty much NEVER use sudo for anything. The only common exception to this I've found is when installing the Passenger module.
That means all operations you want to perform on or with gems, rubies, rubygems, or RVM itself should NOT be performed with sudo.
Also make sure to do rvm use [RUBY] --default to make certain you're always using a ruby other than the system ones.

Related

What's the best way to run a RoR project on my localhost

I have a friend's website code, which is in Ruby on Rails.
I have tried to install RoR on my Mac using instructions at gorails.com
OS : Mac Mojave
ruby -v : ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin18]
rails -v :
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem railties (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/rails:22:in `<main>'
What I tried : I installed ruby, and then rails, using gorails tutorial, and kept getting errors stating version number mismatch.
Keep in mind that creating a new app, worked, but trying to run this existing code is a problem.
So then I uninstalled everything and updated the version using rvm, and since then I am getting this error.
When I cd into the webapp folder and run bundle install, I get errors, such as:
zsh: /Users/abc/.rvm/gems/ruby-2.2.3#hs/bin/bundle: bad interpreter: /Users/abc/.rbenv/versions/2.5.3/bin/ruby: no such file or directory
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your
Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using
RVM are available at rvm.io/packages/openssl.
This project uses a PostgreSQL database, which I have setup already.
If required, I can share the gemfile of this project too.
What is the best way to get this project working?
Am I missing something crucial?
You can't run RVM and RBENV on the same machine. Pick one and remove the other. You're probably best to uninstall both and then pick one, start over.
Uninstall RBENV instructions here or in your case probably brew uninstall rbenv
Uninstall RVM see How can I remove RVM (Ruby Version Manager) from my system?
Close all terminals and then start a new one.
Install RVM see https://rvm.io/rvm/install
Then go to your project, make sure you have the correct ruby version needed by your project. If not, you will need to install with rvm install 2.5.1 for example.
Then run
rvm use 2.5.1 #or some other version
Then you should be able to run bundle install
The rest of the instructions in your link should be ok.

Can't switch default version ruby for rails

I'm desperate, please help. I can't figure out how to change Ruby on Rails to run with 2.0.0, even though I think I've done everything to set 2.0.0 as the default, and rvm -list doesn't even show 1.8.7 as an option. I don't know what files I need to move/what pathways I need to change, and my attempts to uninstall rails have been unsuccessful as there's a "missingBundle" error.
$ ruby - v
returns ruby 2.0.0p247
$ rvm--default use 2.0.0
Using /Users/ericafischer-colbrie/.rvm/gems/ruby-2.0.0-p247
Then,
$ rails -s
Rails prefers to run ruby 2.0. You're running ruby 1.8.7 (2012-02-08 patchlevel 358)
[universal-darwin12.0]. Please upgrade to Ruby 1.9.3 or new to continue.
I've spent a lot of time looking at similar questions posted on stackoverflow and those solutions so far have not yielded any results.
Since you're using rvm, make sure you create a gemset and ruby-version file and install the version of rails you want to use.
E.g inside you're working dir tell rvm which ruby to use, which gemset to use, create both a gemset and ruby-version file:
rvm use ruby-2.0.0#my_cool_project --ruby-version --create
Then
gem install rails
To check run which ruby in that directory to make sure it's ruby 2 - - which rails will show you that it's using the gem of rails inside the ruby 2 my cool project gemset. Should be ok
Looks like you may have used something like sudo gem install rails.
When installing gems, you want to be sure to not use the sudo command.
Try sudo gem uninstall rails; rvm use ruby-2.0.0#myapp --create; gem install rails
Install rvm in your Macintosh
Then do rvm install 2.0.0 or rvm install version(whatever version you need)
Where ever you need a particular version of Ruby(say 2.0.0), do rvm use 2.0.0 and whichever version you need you can switch similarly.
If you are not sure how to install rvm or stuck with something else. Please see link for detailed explanation.
Updated, thanks #Momer.

Which Ruby version am I really running?

I'm running Ubuntu 12.04 LTS, and installed Ruby via RVM.
The problem is, when I type ruby -v into the terminal, it says that my Ruby version is 1.8.7, and using the shotgun gem for Sinatra also says that I'm running Ruby 1.8.7.
But when I type rvm list it shows that the only version of Ruby that I have installed is 2.0.0 and it is my current and default version.
I installed Ruby 2.0.0 via RVM and it is the only version I had installed on my machine.
Now when I tried to install Rails 4 but got an error saying that I need Ruby 1.9 or higher.
How do I know what version am I really on, and how do I set 2.0.0 as my only version?
On your terminal, try running:
which -a ruby
This will output all the installed Ruby versions (via RVM, or otherwise) on your system in your PATH. If 1.8.7 is your system Ruby version, you can uninstall the system Ruby using:
sudo apt-get purge ruby
Once you have made sure you have Ruby installed via RVM alone, in your login shell you can type:
rvm --default use 2.0.0
You don't need to do this if you have only one Ruby version installed.
If you still face issues with any system Ruby files, try running:
dpkg-query -l '*ruby*'
This will output a bunch of Ruby-related files and packages which are, or were, installed on your system at the system level. Check the status of each to find if any of them is native and is causing issues.
Run this command:
rvm get stable --auto-dotfiles
and make sure to read all the output. RVM will tell you if something is wrong, which in your case might be because GEM_HOME is set to something different then PATH.
The ruby version 1.8.7 seems to be your system ruby.
Normally you can choose the ruby version you'd like, if you are using rvm with following. Simple change into your directory in a new terminal and type in:
rvm use 2.0.0
You can find more details about rvm here: http://rvm.io
Open the website and scroll down, you will see a few helpful links. "Setting up default rubies" for example could help you.
Update:
To set the ruby as default:
rvm use 2.0.0 --default
If you have access to a console in the context you are investigating, you can determine which version you are running by printing the value of the global constant RUBY_VERSION.

Mac OS X Mountain Lion "Rails is not currently installed on this system."

I am on a fresh install of OS X Mountain Lion. I have installed rails via:
sudo gem install rails
Everything seems to install correctly, but when I type the rails command (rails s, rails -v, etc), I get this error:
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.
The result of 'which rails' is /usr/bin/rails
I thought it was a path issue, and perhaps it is, but I can see that /usr/bin is part of my PATH.
Any help? Thanks!
UPDATE: I noticed everything on my other mac with same exact OS works pretty well... I just can't remember how I got it to work that way. If I run 'which rails' I see it's in a totally different place /Users/username/.rvm/gems/ruby-1.9.3-p194/bin/rails
If you're using rbenv, don't forget to rbenv rehash after installing/updating ruby.
Use RVM http://rvm.io or rbenv to install newer Rails versions than what come pre-installed with OS X.
Follow examples on the site https://rvm.io/rvm/install/ but basically:
Install RVM: $ \curl -L https://get.rvm.io | bash -s stable
You can then $rvm list known to see what Rubies are available to you (lots). And simply $rvm install 1.9.3 to get the most current version of Ruby (which as of this writing is ruby-1.9.3-p327)
Set that ruby as your default $rvm --default use 1.9.3
Create a default gemset to store your gems $rvm use 1.9.3#mygemset --create --default
Then install Rails $ gem install rails will get you current which today is same as typing gem install rails -v 3.2.9
Just had this issue using rbenv, no idea how this happened, but figured that my ~/.rbenv/shims/rails was empty...
So to fix this:
Cleaned empty shims: find ~/.rbenv/shims -empty -delete
Then regenerate: rbenv rehash (was not overwriting empty one...)
I had the same problem.
After typing:
sudo gem install rails
and installing rails correctly, just close the Terminal window and open again. Then type:
~ $ rails -v
Rails 4.0.2
So, reseting the Terminal window fix the problem.
I think install rvm that will help you
rvm get head && rvm reload
rvm install 1.9.3
rvm use 1.9.3#current --create --default
The last line creates a gem set called current.
Now check to make sure you RubyGems was installed correctly by typing which gem in your terminal. Now update your gems.
gem update --system 1.8.24
Finally install rails.
gem install rails -v 3.2.3
I hope this works, let me know if you have any issues.
Yes, OSX comes standard with a lot of great software for Ruby on Rails, as well as PHP, Mysql, etc. However, sometimes it's better for sustainment purposes to use a 3rd party installer to get everything you want without digging through your /usr/ directory.
I recommend checking out http://railsinstaller.org/
With one easy install, you have everything you could want for a Rails project, including common software people use, and the site even has a tutorial. I recommend going this way. It saves you time. Plus, it comes with an easy uninstaller that it will put in your Applications folder to remove if you're not happy with the configuration. Enjoy.
Actually, /usr/bin/rails script is just a
# Stub rails command to load rails from Gems or print an error if not installed.
(Comment quoted from the very script's source)
If Rails is installed, then it is loaded. Else, the script will throw the error you pasted in your question.
Yet, another alternative to RVM is the awesome rbenv tool.
It is very easy to install (just a simple brew install rbenv) and work with. In my opinion, it is the best way to manage your rubies on a Mac.
However, if you have rvm installed on your machine already, consider removing it from your system by doing rvm implode.
Since setting up a fresh ruby on rails dev environment is a common barrier to most newbies (including myself when i started off with rails) I've put together detailed instructions on how to do exactly that in a blog post, which i will link to below. Hope you will find it useful.
http://blog.parsalabs.com/blog/2013/08/27/setting-up-a-ruby-on-rails-4-development-environment-on-a-clean-mac-os-x-installation/
i got the same error and uninstall rvm then i follow the instructions on this page https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm
i think that help was
rvm requirements
on the terminal.
Our company uses a script to setup each new machine with a Rails dev environment:
We've open source it, give it a try: https://github.com/platform45/let-there-be-light
After a new
gem install rails
do
rbenv rehash
It worked for me.

"File not found: lib" when switching to older rails version using RVM

I currently have rails 3.0.3 and am trying to download and use version 3.0.1. I've downloaded and installed RVM and inputted the following code in Terminal (I have a Mac OS X 10.6.5):
rvm use 1.8.7
rvm gemset create rails3.0.1
rvm 1.8.7#rails3.0.1
sudo gem install rails --version=3.0.1
I use sudo gems because of the user permissions, or my lack there of. Anyway, after I enter the last line of code: "sudo gem install rails --version=3.0.1" I get the following error:
Successfully installed rails-3.0.1
1 gem installed
Installing ri documentation for rails-3.0.1...
File not found: lib
Not only can I apparently not able to switch versions of rails, even though it appears as though I have multiple versions installed, every time I try to check to see what version of rails I currently have I get the following result:
rails -v
/Library/Ruby/Site/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems.rb:214:in `activate'
from /Library/Ruby/Site/1.8/rubygems.rb:1082:in `gem'
from /usr/bin/rails:18
Also, I've already installed Rdoc and Xcode (I've done research and other suggestions pointed to installing both). I'm a RoR newbie, and especially an RVM newbie, so I would love an explanation and a solution to this madness.
Thank you for reading!
I think you went off the rails (ha-ha) right here:
sudo gem install rails --version=3.0.1
The RVM documentation has this to say about that:
DO NOT use sudo...
to work with RVM gems. When you do
sudo you are running commands as root,
another user in another shell and
hence all of the setup that RVM has
done for you is ignored while the
command runs under sudo (such things
as GEM_HOME, etc...). So to reiterate,
as soon as you 'sudo' you are running
as the root system user which will
clear out your environment as well as
any files it creates are not able to
be modified by your user and will
result in strange things happening.
(You will start to think that someone
has a voodoo doll of your
application...)

Resources