Bundler and Rails looking at different gems? - ruby-on-rails

This has driven me crazy. I changed laptop and tried getting my Rails environment working again. Mac OS X has its own ruby, but I used brew and installed new. I installed rails 3.0.5, ran:
bundle install
Then:
rails s
I got this error:
Could not find aws-s3-0.6.2 in any of the sources
Run `bundle install` to install missing gems.
After bashing my head against a wall for a couple hours, I tried just manually installing the gems and it worked! So, apparently, rails and bundler are looking at different places for my gems. Both are from my brew install.
How can I figure out what each is looking at so I can use "bundle install" again?

Rails and Bundle are looking at the gems providing they are in the bundle.
Use the
bundle show
command to see the gems Rails is having access to via bundler.
Also you can examine the Gemfile.lock file.

The gemfile sources mainly from rubygems.org as supposed to rubyforge (which came up when i searched that gem on google). I think the gem command will check both. You can specify additional sources, as mentioned in the readme: http://gembundler.com/man/gemfile.5.html

Are you using pow? I've been having this issue with Pow starting up with one version of ruby, but not the version that I have RVM currently set to.
I have not tried it yet, but this issue on Github mentions the problem and refers people to the Pow trouble shooting here. I've pasted the contents below:
RVM
Incorrect ruby or gemset is being used
Create a .rvmrc at your project root. See rvmrc docs.
System-wide RVM install
If you have a system-wide RVM install and are getting the error LoadError: no such file to load -- bundler/setup, run rvm info to find out where rvm is installed on your machine, then do this:
echo "export POW_RVM_PATH=/usr/local/rvm/scripts/rvm" >> ~/.powconfig
Where /usr/local/rvm/ is the location of your rvm installation.
Then restart POW by killing it in the Activity Monitor or in Terminal.

Related

RVM and Bundler, byebug gem: C extensions are not supported

I have been using Ruby on Rails with postgresql and something suggested that I should install RVM which I did (I think it was to utilise Phonegap). Since I put RVM in place I have been unable to execute bundle install which in turn means that I can no longer run other rails commands.
Lots of reading hasn't really given me an answer but I have lots of ideas. Maybe someone can help focus those ideas into a solution?
When I run bundle install there are 3 gems that seem to be causing the problem, but I think they are interlinked. They are byebug 8.2.2 and pg 0.18.4 and binding_of caller 0.7.2
The contents of byebug-8.2.2/gem_make_out are as follows:
/home/damo/.rvm/rubies/jruby-9.0.5.0/bin/jruby -r ./siteconf20160927-16151-j7mhkf.rb extconf.rb
NotImplementedError: C extensions are not supported
<top> at /home/damo/.rvm/rubies/jruby-9.0.5.0/lib/ruby/stdlib/mkmf.rb:1
require at org/jruby/RubyKernel.java:937
(root) at /home/damo/.rvm/rubies/jruby-9.0.5.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1
<top> at extconf.rb:6
extconf failed, exit code 1
When I look at byebug issues it simply says that byebug doesn't support jruby.
I did not have any issues before I installed RVM and I'm sure I read that byebug was hardwired into Rails 4. I wanted to tell you my Rails version but rails -v gives me a response of
Could not find proper version of railties (4.2.5) in any of the sources
Run `bundle install` to install missing gems.
Which seems to be my Catch 22!
This kinda sounds like you're not using RVM in a login shell. In Bash you can run bash -l, then source ~/.bashrc (or whatever contains your rvm invocation lines). After that, try rvm use ruby-2.2 (or whatever), and if you don't get "RVM is not a function" error, then you should be good to go.
Note that under RVM you'll probably have to do gem install bundler manually for each distinct ruby version (and gemset), because ruby (and gemsets) under RVM live in their own worlds, and system bundler tends to be old. If you're reusing ruby installations and either not using or sharing gemsets, bundler may already be up to date.
So: use a login shell, do rvm use <your_favorite_ruby_version>, install bundler if necessary, then bundle install.
Last but not least, I like to use .ruby-version files so I don't have to switch rubies and gemsets manually, and I can tell if everything's working from the output of rvm info.
Where you using jruby before you installed rvm? Seems like your default ruby changed to jruby as opposed to whatever you where using before (system ruby?).
Try running
rvm use system
in the root of your rails project then try the bundle install and see if that fixes it. If it does then then can use setup .ruby-version files to control which version of ruby you use per project.
Or else type
rvm use system --default
to set your default ruby back to the system one and continue like you where preciously.

How do I know if I'm using rbenv

After reading about Ruby gems and having no idea what rbenv or RVM was, I figured I should probably have one of the two.
I tried installing rbenv using Homebrew however it told me I had already installed rbenv. I always seem to have problems adding gems and usually end up using the sudo command to get it to work (which is a horrible idea I assume).
I discovered I had these problems when I was trying to add the braintree API gem and got an error whenever I tried to start the server.
Commands I tried:
gem install "braintree"
bundle install
sudo gem install "braintree"
The error received from running rails server was:
"/config/initializers/braintree.rb:2:in `<top (required)="">': uninitialized constant Braintree::Configuratio (NameError)"
To take it from the top, rbenv and RVM are Ruby version managers. This means that you can have multiple versions of Ruby installed on your computer at once and select which one you would like to use. I have used both and personally like rbenv's approach.
With that said I think you need to remove the quotes from around the name of the gem you are installing.
Also, in your Gemfile do you have the braintree gem listed? It should be as simple as gem 'braintree'.
If you have multiple versions of Ruby installed or even if you just have the system Ruby and a version installed with RVM or rbenv you may be starting your Rails server with the wrong Ruby version (ie it is missing the gem). You can see if it is using rbenv by typing which ruby and it should print something out with .rbenv/ whatever. If not you need to set rbenv as your current ruby. You can do that like rbenv global 2.1.1 where 2.1.1 is the version of ruby you installed with rbenv. If you haven't installed a version with rbenv you can use ruby-build and do rbenv install 2.1.1 or whatever version you want. Then when you launch your Rails server prefixing the command with bundle exec.
You can set a local ruby-version for your directory by executing rbenv local 2.1.1 once again where 2.1.1 is the version you want.
Reading the rbenv docs will go a long way.
To check if you are using rbenv, simply use this
rbenv
*check if 'rbenv' commands were listed
Same with rvm use
rvm
Run the command rbenv in terminal. If you have rbenv installed, it will list some help commands. If rbenv is not installed, it will output something like "No command 'rbenv' found"
Run the command rvm in terminal. If you have RVM installed, it will list some help commands. If rvm is not installed, it will output something like "No command 'rvm' found"

Could not find RubyGem railties

I try to create new app with "rails new" command however getting this error:
'report_activate_error': Could not find RubyGem railties (>= 0) (Gem::LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:244:in 'activate_dep'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:236:in `activate'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:1307:in `gem'
from /usr/local/bin/rails:18
Any idea why?
by the way I am working on Ubuntu
gem list
*** LOCAL GEMS ***
it is empty but I installed rails just before
I have encountered the issue before.The solution is :
you must use comand gem install rails, not sudo gem install rails.
I encountered the same problem and found the following solution Here which was mentioned here. Hope it helps
After you installed RVM and after you set the default Ruby version in RVM, you need to re-install all ruby gems, e.g.
gem install rails
you need to install those gems as the user, not as root.
Because from now on RVM will keep track of all installed gems by the ruby version which was used to install them!
You need to install RVM (I don't know it is the best solution but it works) then use such rails commands like rvmsudo rails new or such. I use rails and ruby command with including rvm or rvmsudo phase and all of them start to work.
Do you have multiple Ruby installations on your system? Maybe you have installed some package (like Heroku with full installation) and you are using the 'new' Ruby installation. I have uninstalled the last Ruby and everything seems to be fine.
Edit: Not everything is fine... yet. Under Windows you will have to edit Heroku.bat (in your Program Files/Heroku path) and change the path to Ruby installation folder.
Install rvm and try it again to install rails
RVM provides a very great way to manage your gems in Gemsets
for multible ruby installations.
On the offizial rvm site is a installation tutorial
http://beginrescueend.com/

"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...)

gem path reverts back to previous path

just recently installed ruby 2.3.0 and rails 4.2
ran bundle install for the first time and my app successfully ran from my local server.
added a few gems, and once again ran bundle install... it appears that my previously installed gems were once again being installed.
tried running rails server once again and this came out.
-bash: /usr/local/bin/rails: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
just making a wild guess here, but i think the gem folder is reverting back to my old folder which is ruby 1.9.1
any form of help would be greatly appreciated.
You can read about different ways to set the app/project environment at rvm project workflows
if you are using rvm to manage the rubies, just add this line at the top of your gem file..
ruby '2.3.0' #or the target version of the app
or
#ruby=2.3.0
and cd back into the directory.. you'll get a warning but just ignore it. now every time you change back to you app directory it'll change the version to the one mentioned in your gem file. the default might be set to some other version..
you can also use
bash --login
rvm use '2.3.0' --default
to set the default version of ruby system wide.
if that doesn't work.. try to check if the correct ruby version is present by
rvm list
and then try using it by
bash --login
rvm use '2.3.0' #or the target version
and to every time switch to the latest version don't do anything above except when installing the version set it to default.. but you'll have to install all the gems again for every binary ruby you install..
P.S. Fixing ruby version for a project/app is a good and safe practice, so I'd recommend you to use the any approach to fix a ruby version for the app, mentioning it in Gemfile is clean, makes sense to me when you only need to set the ruby version.
Note. Do whatever is in #Shrikant1712's answer first if you haven't already or you might run into issues.
You have need to install gem bundler using gem install bundler command and then again try to use bundle install command.
(Here I am assuming you have used RVM for installing ruby.)
Still you get same type of error then that means your rvm is not properly set. Please check your $PATH from the following files
~/.profile
~/.bashrc
~/.bash_profile
~/.gemrc
You can use source ~/.rvm/scripts/rvm for setting the rvm.

Resources