Ruby 2.1.1, Could not find Railties - ruby-on-rails

Working with this repo, which requires ruby 2.1.1 and rails 4.1. I am using RVM, and I have downloaded ruby 2.1.1, but I am getting this error when I type rails -v. I feel like I need to start completely over, but do you see anything below that may have a relatively simple solution?
When I type rails -v, I get this error:
/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/dependency.rb:298:in to_specs': Could not find 'railties' (>= 0) among 14 total gem(s) (Gem::LoadError)
When I type in ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
Bash_Profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM$
RVM Gemset List
gemsets for ruby-2.1.1 (found in /Users/me/.rvm/gems/ruby-2.1.1)
=> (default)
demo
global
myapp
rails
rails4.1

Try to run these commands:
rvm use 2.1.1#rails-devise --create
bundle install
rails -v
evan: but not when I generate my own app because it gives me an error before I can create it.
Lets discuss some basic concepts of RVM, that can help you:
Every project should contain its own gemset. Repo contains two special files in root folder:
.ruby-gemset - contains unique, project-specified name of gemset
.ruby-version - Ruby version number, to see list of available: rvm list
These files should be placed in root folder of every project on your computer.
When you open project from the linux Terminal, rvm scan for these two files, read them, and activates needed ruby version and loads necessary gems automatically.
Note: each rvm session is alive in current Terminal session only. You should reactivate it for each Terminal session separately.
If current gemset name is not specified, RVM uses default rvm gemset (unnamed gemset).
I uses default gemset for my default projects, when I need quickly create something temporary. But I noticed, that default gemsets of beginners reminds a dump of different unsystematic gems. Some of them can relate to same Gem modules, but with different versions.
Such kind of versioning, may leads to different strange errors and problems, what happened with you. If you want use a default gems set (I suppose you is a NOT rails-developer, based on your profile), open your project directory, and perform in terminal:
rvm gemset empty ''
rvm use #default --default
bundle install

Related

RVM switching Rails Versions

The situation is that my default gemset on my computer points to rails 5.0.0. However: I have an app that uses a really old rails version. Lets say for this example the app uses: rails 2.1.1.
Does my machine automatically switch to rails 2.1.1 when cd'ed into this app because rails 2.1.1 is specified in the Gemfile? Or: do I need to explicitly create a gemset in order for my app and my machine to do things the "rails 2.1.1 way" (as opposed to doing stuff the "rails 5.0.0 way which is the rails version in my default gemset)?
My concern is that perhaps if my machine thinks I am using rails 5.0.0 instead of rails 2.1.1 while developing inside the app: then rails commands such as generators might create files and do stuff "the rails 5.0.0 way" as opposed to the "rails 2.1.1" way.
Hopefully this makes sense. Here is what I would do in order to "explicitly" state via a Gemset that this app uses rails 2.1.1
Example:
I create a gemset that is to be specified for any app that uses rails 2.1.1
rvm gemset create rails_2_1_1
I specify the ruby version to use on this gemset
rvm use 2.2.1#rails_2_1_1
I then install that old version of rails onto this gemset:
gem install rails --version=2.1.1
Now this gemset uses rails 2.1.1.
Now at the root of my app I specify a .ruby-gemset file that tells rails: "Make sure you are doing stuff the rails 2.1.1 way and not the rails 5.0.0 way:
#.ruby-gemset
rails_2_1_1
I want to be sure that if another rails version is specified in an app's Gemfile than is in my default gemset: then developing within that app will do everything within the context of the rails version specified in the Gemfile as opposed to the rails version in the default gemset.
That's not a problem with RVM and Rails. Using the Gemfile is the best way to do this, IMHO! In your Gemfile, you can specify which ruby and which gemset within that ruby to use.
Set Default Ruby/Gemset --for system
First, lets establish that default ruby for the system on 5.0.0. This will allow any new/existing Rails projects to default to this ruby version (except for those projects that override with the Gemfile):
rvm use --default 5.0.0
..and of course, if you want it fixed to a specified gemset:
rvm use --default 5.0.0#my_default_gemset
Set Default Ruby/Gemset --for Rails specific App on Gemfile
Example 1
If you want to setup your rails app to utilize the RVM gemset 2.2.1#rails_2_1_1, similar to the RVM command below...
rvm use 2.2.1#rails_2_1_1
In your Gemfile, specify right below the source line the following two commented lines:
source 'https://rubygems.org'
#ruby=2.2.1
#ruby-gemset=rails_2_1_1
Now, when you cd into your rails' app directory, you should receive the following message, or similiar:
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does
that too, you can ignore these warnings with 'rvm rvmrc warning ignore
/my/rails/app/path/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore
allGemfiles'.
You can double check your results:
rvm list gemsets
ruby-2.2.1 [ x86_64 ]
ruby-2.2.1#global [ x86_64 ]
=> ruby-2.2.1#rails_2_1_1 [ x86_64 ]
ruby-5.0.0 [ x86_64 ]
ruby-5.0.0#global [ x86_64 ]
Example 2
Another example using ruby-2.0.0-p247#rails-4.0.0, example RVM command...
rvm use ruby-2.0.0-p247#rails-4.0.0
In your Gemfile, specify:
#ruby=2.0.0-p247
#ruby-gemset=rails-4.0.0
You can also create rvmrc file into your project directory then it will switch rvm automatically
Please follow the process to create rvmrc file.
Go to project directory
rvm use 2.2.1#rails_2_1_1
rvm --rvmrc --create 2.2.1#rails_2_1_1
I think it would help you.
You can create a .ruby-version file in your project's folder and RVM will automatically switch to the correct Ruby. Something like this:
$ echo '2.1.1' > .ruby-version
You just need to make sure you have that version installed, eg.:
$ rvm install ruby-2.1.1
First of all, I recommend against using .ruby-gemset file, because Gemfile already has everything you'll need. .ruby-version is obsolete too, because Ruby version can be specified inside Gemfile as well:
source 'https://rubygems.org'
ruby '2.3.1'
gem 'rails', '~> 4.2.7'
...
Now about Rails versions. As long as you run commands with bundle exec, these commands' versions will be exactly as stated in Gemfile.
There are also binstubs scripts inside projects bin/ folder. They're the most preferable way to run commands, because they're usually tweaked for project needs (for example running spring along with your command) and they ultimately run bundle exec anyways.
So the proper way to do things, is to run ./bin/rails, which can be tedious. That's why I recommend using helpers. For example, oh-my-zsh project has out-of-the-box rails plugin. First few lines (read below for explanation):
function _rails_command () {
if [ -e "bin/rails" ]; then
bin/rails $#
elif [ -e "script/rails" ]; then
ruby script/rails $#
elif [ -e "script/server" ]; then
ruby script/$#
else
command rails $#
fi
}
function _rake_command () {
if [ -e "bin/rake" ]; then
bin/rake $#
elif type bundle &> /dev/null && [ -e "Gemfile" ]; then
bundle exec rake $#
else
command rake $#
fi
}
alias rails='_rails_command'
compdef _rails_command=rails
alias rake='_rake_command'
compdef _rake_command=rake
When you run rails, this script checks if bin/rails exists (Rails 5 and 4 default) and runs it instead. If not, script checks for script/rails (Rails 3 default) and script/server (Rails 2 default). So basically you have all versions covered. Same is for rake.
With this plugin you never need to worry about extra commands. Always simply run rails. You just install it once and forget about it.

can't install new Rails app; RVM 'global' gemset missing from main directory but visible in app sub-directories

When I try to create a new Rails app in the directory in which I keep all my Rails apps, I get the following 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.
I've recently been working with an RVM tutorial, so I thought it might have something to do with a gemset I had created. I typed 'rvm gemset list' and found the following:
gemsets for system (found in /Users/rickthomas/.rvm/gems/system)
=> (default)
*
But the weird thing is, I cd'ed into the directory of one of the apps, and ran the same command, and found this:
gemsets for ruby-1.9.3-p429 (found in /Users/rickthomas/.rvm/gems/ruby-1.9.3-p429)
=> (default)
global
When I run the 'rails --version' command in the main directory, I get the message to run 'sudo gem install rails', but when I run the same command from within the app directory, I get this:
Rails 3.2.12
Kinda confused why I all of a sudden can't create a new Rails app, since the last one I created was this morning, a day after I finished the RVM tutorial, and didn't make any gemset changes since then.
It looks like your "system" ruby doesn't have the Rails gem installed. You probably don't want to be using the system ruby anyway. How about you try this:
rvm use 1.9.3 # switch to your Ruby 1.9.3 that the other app used
gem list # make sure rails is listed
gem install rails # (only if rails was not listed)
rails new myapp
There is nothing weird about the "weird thing" you observed. When you cd into a directory, RVM looks at files like .rvmrc, .ruby-version, and .ruby-gemset in that directory and it automatically changes your environment to match. You can run "rvm info" to see what kind of environment you are currently in (I usually focus on the GEM_HOME and GEM_PATH variables). In this case, cd'ing into your Rails app directory caused RVM to switch you to Ruby 1.9.3, and that's the Ruby where you had the rails gem installed. Seems normal to me.

How rvm manages Gem/gemsets

I am wondering how RVM manages the gem/gemsets. For instance, I have by default been using ruby 1.9.2#global and installed rails 3.1.3 in this environment. Later I copied a rails project from other, which is based on rails 3.0.10. By cd into the folder, I ran rails -v, it recommended me to run bundle install. I did so. After this, lots of gems were installed including rails 3.0.10. But when I do rvm 1.9.2 do gemset list, there is no new gemset( this is expected though). Then how do I manage the two versions of rails?
Thank you in advance
You can have more than one path into your Gem.path.
Try running ruby -r rubygems -e "p Gem.path" and check the output, you'll see that both #global and your current gemset are included.
Rubygems use the $GEM_PATH variable to figure out where to look/install gems, and that's one of the things RVM sets when you change a ruby version/gemset.
Also, it might be worth to look at a few environment variables RVM sets. Run this:
env | grep -i rvm||path
There might be a few extra ones (including $PATH), but you'll general you'll see a lot of RVM environment variables.
That's why some people like rbenv, a simpler way to manage ruby versions.

Questions regarding RVM

I am exploring the world of Ruby and RVM. I am going through a lot of documentation and trying out RVM, but I am a bit confused about the entire work flow. I am writing down the workflow as I understand it. Can someone please take a look and see if this understanding is correct?
I am using a Mac.
RVM is essentially a script that allows us to manage Ruby environments for development purposes.
RVM allows switching between different versions of Ruby with rvm use 1.9.2.
To use a particular gemset with the current Ruby version, we need to create a gemset using
rvm --create gemset rails235
Install the gem using gem install rails -v=2.3.5
Q: What happens if I did gem install rails -v=2.3.5 prior to creating a gemset? Will there be two copies of the same Rails installed under RVM's Ruby 1.9.2?
Q: What happens if I install 2.3.5 and 3.1.0 prior to creating gemsets and then create a gemset for each version?
Q: where does rvmrc come into picture in the whole story?
Any other information that helps me get this straight is extremely helpful.
#Kiran, this is in reference to your comment above. When you install a different version of ruby with rvm, it'll add to this list:
$ rvm list
rvm rubies
=> ruby-1.9.2-p290 [ i386 ]
On my system, I've only got one version running (for now). This helps too
$ rvm gemset list
gemsets for ruby-1.9.2-p290 (found in /Users/mike/.rvm/gems/ruby-1.9.2-p290)
global
=> mg_diaspora
rails3
railscasts
ruby
sorcery
The practice is to install common gems into your global gemset and create/use sets for everything else. I tend to keep pry and others in the global gemset. As Mike K. said, you'd never do #2; if you did do such a thing, I would imagine global having priority.
#3 .rvmrc
You can do things like this in the file:
rvm use 1.9.2#rails3 --create
This will ensure whenever you 'cd' into the directory, it'll switch to 1.9.2 and it's 'rails3' gemset; the following attribute ensures the gemset will be created if it doesn't already exist.
Update
Ex: if I say rvm use 1.9.2#rails3 --create how does this pick the version of rails3.1.0 gem
Because by the time this rails3 gemset is created I already have 2 versions of rails gems?
That's easy - when you run bundle install it creates a Gemfile.lock; this essentially 'locks' the gems that your application is set to use. You've never require two different versions of rails in a single Gemfile anyways - that's just ridiculous =)
1) Rvm automatically creates an #global gemset per interpeter so if you did what you state in the first question you'd have a 2.3.5 in the global gemset.
2) I'm not sure why you would do this.
3) rvmrc is just where you can specify environment info like bashrc, i use it to specify my default architecture for instance. It gets read when rvm gets sourced in your profile.
Basically global is a mix-in for all other gemsets under a specific interpreter. So, if you put rake and say bundler into the global gemset, and then create and enable your own gemset under that specific ruby, it will have both the gems you install in that gemset AND global.
You will see it as a single gemset though. Also, if you attempt to delete a gem that is in global while still in, say, mygemset you will not be able to delete it. This is to protect other gemsets from having gems mixed in from global that they rely on from being removed. You would have to either explicitly change to global or execute something like
rvm 1.9.2-p290#global exec gem uninstall rake -v='0.9.2'
Also, bear in mind that there is a significant difference between 'default' and 'global'. The 'default' gemset is not really a gemset perse. This is selected when you do something like
rvm use 1.9.2
Notice you did not select a gemset in the above command. This is where default lives and plays. When no gemset is selected, default becomes active and global totally disappears. To load default, you would modify $rvm_path/gemsets/default.gems as these are the list of gems to be installed into each interpreter's 'default' set. The other file there is 'global.gems'. This is used as you would surmise; to load a default set of gems whenever you install a new interpreter under RVM into the global gemset, which is shared by all other gemsets for that Ruby, but not for 'default'.
Please see https://rvm.beginrescueend.com/gemsets/basics/ for more information.

RVM finding system gems' executables

I have installed RVM along with ruby versions. However if I fire up the console and run the command rails server, bundle install, etc. I get this error
bash: /usr/bin/rails: /usr/bin/ruby1.8: bad interpreter: No such file or directory
But if I run rvm use 1.9.2 first, then everything is ok. I tried using `rvm use --default 1.9.2' but nothing changed. Does this mean it uses a different ruby from the ones in RVM? Thanks in advance!
Explanation of rubygems bin folders and PATH
Oh. You didn't have rails installed in your rvm ruby, but you did in your system ruby.
Individual gems, like rails can have a bin directory that will contain executable helper scripts. Your system default rubygems is making symlinks from your system /usr/bin/ dir into the gem's bin folder for these helper executables.
RVM provides a similar facility, except instead of polluting the system /usr/bin dir, it just appends its ~/.rvm/gems/#{rvm_gemset_string}/bin folder to the PATH environment variable.
Importing system Rubygems list into your new rvm rubies' gem directories
RVM by default will not import your gems from your system ruby installation into your rvm ruby installs. It makes a full clean fork of the entire ruby system including rubygems (the gem 'rubygems') and rubygems' gem list. When you rvm install 1.9.2 it's like you've made a completely new install of everything used with ruby.
If you'd like to get all your system ruby gems that you were previously using into your preferred rvm ruby, try this:
rvm use system
rvm gemset export system.gems
rvm use 1.9.2
rvm gemset import system.gems
#You'll now have all your system gems reinstalled to your new ruby version
Original Answer/ Edits from #Telemachus
Try moving the lines that source rvm to the end of your ~/.bash_profile or ~/.bashrc (whichever you have it in):
'[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function'
.
bash: /usr/bin/rails: /usr/bin/ruby1.8: bad interpreter: No such file ...
| | ^--------------------------------\
^ Bash, not rvm; ^/usr/bin/rails, not ~/.rvm/gems/*/bin/rails; |
Some ruby leftover from a previous install in the os
You have rails installed in /usr/bin, which is probably before the rvm ruby bin path in your bash echo $PATH variable, so it's finding the system rails install (/usr/bin/rails, a ruby script) which starts like this:
#! /usr/bin/ruby18
You've gotta make the conflict stop happening, the best of all possible ways is making sure that RVM's bin dir is at the beginning of your PATH. This happens in the #Load rvm environment script that you added to your ~/.bash_profile when installing rvm. If you installed rvm as a system library rather than just for your user, this will be different.
If you get to that case, ask #Telemachus.
You'll then need to ensure you've gotten the rails gem installed in your new rvm ruby as above.
Acceptance Test:
You'll find that when you've done rvm use 1.9.2, then which ruby will return something like ~/.rvm/rubies/1.9.2/bin/ruby, and which rails should return something like ~/.rvm/gems/*/bin/rails.
I just solved the same problem on Windows Vista.
My console was giving me this message:
$ rails -v
sh: /c/RailsInstaller/Ruby1.9.2/bin/rails: C:/Projects/railsinstaller/Stage/Ruby1.9.2 /bin/ruby.exe: bad interpreter: No such file or directory
I just edited the first line of this file:
C:\RailsInstaller\Ruby1.9.2\bin\rails
And made it point to the correct location for ruby.exe, on my system, like this:
#!C:\RailsInstaller\Ruby1.9.2\bin\ruby.exe
Et voilĂ , problem solved!
You need to run rvm use --default 1.9.2, not just rvm use --default.

Resources