Path's issue with bundler, to change or not to change? - ruby-on-rails

I'm trying to setup a new rails 3 project with bundler, but i ran into issues with bundler.
I'm on rails 3.0.3 with ruby 1.8.7
When trying to do
$ bundle exec rake db:migrate
I get the following error
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/dependency.rb:52:in `initialize': Valid types are [:development, :runtime], not nil (ArgumentError)
Same goes for when I try to issue a regular rake task in my terminal, one like
$ rake -T i.e., only then I get the error:
uninitialized constant Bundler /Users/daniel/cc/contributie_data/Rakefile:4 (See full trace by running task with --trace)
I've been reading some other questions regarding this problem, therefore i've learned it has something to do with paths...
$ which rake
/usr/bin/rake
$ which ruby
/usr/local/bin/ruby
Can anyone give me some suggestions about what could be happening here?
And even more important, how I can get bundler to play nice with rake..
Thanks for any input on this, much appreciated!

I got the same error (I'm using rvm). It turned out that in both my .profile and .bashrc was the following statement:
export PATH=~/.gem/ruby/1.8/bin:$PATH
So this path was taken instead of the rvm path. I commented these lines out and now everything works fine

Try to delete Gemfile.lock. It usually helps with
Valid types are [:development, :runtime], not nil
error.

Oh man, I just when through this today.
I did an update, and my rvm broke -- started throwing up on missing scripts and the like. I just got finished completely reinstalling rvm and my rubies.
it's not great, and it takes a while but it's what I did to get back to a working state.
Started here. How can I remove RVM (Ruby Version Manager) from my system? Ended up going through and installing fresh.

I too face the same issue and resolved it with the help of this link github:bundler
Modified a line in the file lib/bundler/resolver.rb which is reside inside bundler gem. Remove * mark from the line d = Gem::Dependency.new(base.first.name, *reqs)
like this:
reqs = [dep.requirement.as_list, base.first.version.to_s].flatten.compact
d = Gem::Dependency.new(base.first.name, *reqs)
to
reqs = [dep.requirement.as_list, base.first.version.to_s].flatten.compact
d = Gem::Dependency.new(base.first.name, reqs)
*modifying content of a gem directly is not a good practice. Posted this just to show another way to resolve this issue.

Related

Ruby rake loaderror - bundle exec rake not working

I'm trying to run the command rake db:migrate but I keep getting this error:
/Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `load': cannot load such file -- /Users/[name]/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/specifications/default/bin/rake (LoadError)
from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `<main>'
from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Trying bundle exec rake db:migrate also gives me the same error.
Is there a way I can solve this issue? (I'm on Mac OS X 10.10.5)
EDIT: The first letter of my [name] in the error is upper case even though in my system, it's lower case.
EDIT [PARTIALLY SOLVED]: So I was using Ruby version 2.2.1 and I was supposed to use 2.1.2. Although this did not fix the rake command error, I was trying to run rails server which successfully ran after changing my Ruby version.
If none of the above mentioned comments worked for you, then I suspect you may need to update rake gem. Try:
bundle update rake
See if that fixes the issue. If not, let me know. I will update the answer.
/bin/ruby_executable_hooks.rb error indicates that the error is coming from a Bundler hook. Try to delete the .bundle directory in your project root path and see if the error is gone.

Persistent Rake DSL method warning

Alright, well I'm trying to fix this problem again. I followed this fix to eliminate the error by reverting to version 0.8.7, which worked the first time. However, now I'm trying to use cucumber and I'm getting it all again.
I tried it again by running gem uninstall rake -v=0.9.2.2 which lists all the gem dependencies. Successfully uninstalled. Then I ran bundle update rake. Using rake (0.8.7). Cool. rake -V. rake, version 0.9.2.2. wat. Same problems return. What am I missing? I thought 9.2 was supposed to fix this bug anyway?
I think this fix is obsolete. Rake 0.9.0 got fixed, and 0.9.2.2 is certainly working. You want to uninstall and completely eradicate rake 0.8.x. Try something like:
gem list -d rake
The -d switch will show the installation directories. If you're using RVM, there may be multiple search paths that get hit, running rvm info will tell you the search path and preference ordering. Depending on the system you're on, your OS may also ship with an old rake version. Try uninstalling everything other than the local gemset (if using RVM) or the latest rake (if not using RVM).
The problem with the rake gem uninstall sounds like you have Rake in your default gemset, check ~/.rvm/gemsets/global.gems It will no doubt have rake in it

How to solve "uninitialized constant Dependencies" error in rake?

I am trying to build Noosfero (http://noosfero.org/), a project done in Ruby, but I am pretty new in Ruby and Linux (my current environment).
I am following the instructions in their tutorial (http://gitorious.org/noosfero/noosfero/blobs/master/INSTALL and http://gitorious.org/noosfero/noosfero/blobs/master/HACKING).
I was supposed to run an apt-get install with many packages, everything worked except for libgettext-ruby-data, to which I get a message that "E: Package libgettext-ruby-data has no installation candidate".
I then download the source and try to run "rake db:schema:load", which I get the following error:
"rake aborted!
uninitialized constant Dependencies
/home/user/noosfero/Rakefile:10"
My rake file is the following:
require(File.join(File.dirname(FILE), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails' #this is the line that the dependency can't be found
I searched around and found this question here: Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) , but changing the config files didn't help and I could wasn't able to downgrade my RubyGems because I do not know how to do that (gem -update returns a message that I have to do that using apt-get, but I can't find out in which package the gem program is).
The first time I run Rake, I get a message saying:
"I: Installing Debian-installed Rails from /usr/share/rails into vendor/rails.
I: Please note that the recommended Rails version is 2.1.0, and that other versions might not work"
But I don't know how to downgrade my Rails version.
I've got many paths to follow, so I've got many questions, I hope you can help me:
1- Does anyone knows how to fix it directly?
2- How can I downgrade Gems?
3- How can I downgrade Rails?
4- Where can I download gems and how can I install it? (The documentation provides a link, but this link is VERY strange: http://www.yotabanana.com/hiki/ruby-gettext.html?ruby-gettext ).
Any help is very appreciated.
Thanks,
Oscar
Edit: can this error be a problem in the project I downloaded and not in my environment? After some research I am starting to think it is, can it be?
It would help if you share your rake version, by the way.
In the meantime, take a look at this:
https://github.com/jimweirich/rake/issues/33
(Only valid for rake 0.9.0, though).
This was a version conflict I had with the project I was trying to build, not it is solved :)
First of all, I'm a Noosfero developer and I need to admit that the process of preparing the environment to run Noosfero right now is pretty nasty (unless you only want to run it in the production mode since we've got a debian package). But this problem is close to an end since we're a building a vagrant box (for more info see http://vagrantup.com/) to noosfero. Things are going to be much better. But regardless all this nastiness and not having the box yet, Noosfero was supposed to run if you followed all the steps in the INSTALL instructions. Let me try to help you.
Are you using Rails 2.1.0? The best way to do so is to uninstall rails from your system (if you installed through apt-get) and install through rubygems:
gem install rails -v=2.1.0
To avoid problems ensure that there isn't any other version of rails installed through rubygems (gem list).
If you still having problems to run the schema load, run it with --trace and post it here.
If you have other problems you can try contacting us through noosfero-dev#listas.softwarelivre.org or the irc #noosfero at FreeNode.

running rake fails with Gem::GemNotFoundException ERR

Backstory:
New to rails and attempting to install Passenger on a Mediatemple DV server. I am following and somewhat modifying this CentOS guide here since MT currently does not have any recommended 'how tos' regarding setting up a Rails production environment http://www.freshblurbs.com/installing-ruby-rails-3-centos-nginx.
I have fresh-ly installed gem and then ran gem install rake as root. Now, anytime I try to run
rake some_task
I get the following error
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:370:in `bin_path':
can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)
from /usr/local/bin/rake:19:in `<main>'
rake is installed here /usr/local/bin/rake
$PATH is /usr/kerberos/sbin:/usr/kerberos/bin://sbin://bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/bin:/usr/local/bin:/root/bin:/usr/bin:/usr/local/lib
output of gem which rake is /usr/local/lib/ruby/1.9.1/rake.rb
... and unfortunately that's about all I got up my sleeves. What am I missing that's causing this to bomb?
Thanks in advance!
I have the similar problem with rake, but in ruby 1.9.2.
http://betterlogic.com/roger/2010/11/ruby-1-9-2-rake-woe/
Maybe in your case it will be helpful too.
Not sure this'll help maybe it will.. maybe not..
But run a gem list first and make sure both rake and also the passenger gem show up. I think I remember seeing a similar error that was misleading trying to setup a production server recently when running:
passenger-install-apache2-module
face palmed when I realised i hadn't installed the passenger gem yet

Rails and Rake commands hang and do nothing at all

I don't know why but when I run rake commands in my rails project, nothing happens. Also rails server does nothing. Any suggestions?
you can add an "ruby -rtracer" to the begining to see where it is hanging.
The solution for me entailed exiting rails console -sandbox.
I think sandboxing console puts a lock of some sort on the database.
You could try adding the --trace argument to your rake calls to see if that sheds any light on where it is getting stuck. Failing that there may be some information in the logs.
It does suggest that something that is getting stuck during setting up your environment which may be something you've added to environment.rb.
Are you using rvm?
A lot of advice these days is to install ruby within rvm and rails within an rvm gemset. If you've done this, then you need to remember to do commands such as these at the start of your terminal session:
rvm use 1.9.3
rvm gemset use ruby193rails3
I found if I forgot to do this, then the rake command, even just a simple rake --version , would hang and thrash the disk.
...which all seems a bit fragile. I guess it's latching onto part of rails but with some files missing due to rvm not having moved them into place or something.
Spring has a bug in Rails 4.1 which also causes this (not the OP's issue, based on date). For those googling, I solved this problem my typing "spring stop". Spring will be automatically restarted the next time you run "rails ". To give proper credit, I found this information from this blog:
http://www.dixis.com/?p=754
What fixed this for me was running
bin/spring stop
and then running my rake command after.

Resources