Rake command using the wrong path - ruby-on-rails

Recently I installed jruby and put it in my home directory. This apparently hijacked rake:
$ which ruby
/usr/bin/ruby
$ which rake
/home/user/jruby-1.5.5/bin/rake
Which seemed to be causing problems. So I moved the jruby folder and reinstalled rake, which at first seemed to fix it:
$ which rake
/usr/bin/rake
But when I run rake it's still trying to use the one in jruby:
user#user-desktop:~/rails/appname$ rake db:migrate
bash: /home/user/jruby-1.5.5/bin/rake: No such file or directory
How do I fix this?

Try RVM. It is invaluable for isolating different Ruby versions. Once installed do
rvm install jruby
That gets you a separate environment for running JRuby. You can switch between versions with
rvm system
rvm jruby

Related

Rails rake updating issue - Could not find rake-10.4.2 in any of the sources

I'm attempting (without much success) to run rake db:migrate on a rails project, however it returns:
Could not find rake-10.4.2 in any of the sources
Run bundle install to install missing gems.
I ran bundle install and worked fine - installed rake 10.4.2, however when I ran: rake --version (for some reason you can't do rake -v ???) and it shows: rake, version 0.9.6
I ran bundle update rake and returned my list of gems and then: Your bundle is updated!
Why isn't rake updating? Is there something I'm doing wrong (I'm new to rails btw - so this is probably really simple)
Any help is really appreciated
TL; DR: gem install rake -v '10.4.2'
So, I had this problem myself. I wanted to know why rails s would work yesterday and not today.
First I checked if I was in the correct directory, I was.
Then I re-ran bundle install to make sure rake was getting installed. It was, and I was able to see it in my Gemfile.lock
So I figured my gemset might be corrupt (I use RVM). rvm gemset empty then bundle install
Still, whenever I ran rails s, I got this error. bin/rails s worked, as well as bundle exec rails s. But I don't want a prefix, I want rails to work (It works in other rails projects)
Eventually I tried gem install rake and it worked! I recommend adding -v '10.4.2' to the command so that you get the correct rake version. Now when I which rake, I get the gemset for my project: "/Users/cm022291/.rvm/gems/ruby-2.2.1#project_gemset/bin/rake"
and when I run rails s the server starts successfully.
Try typing
bundle exec rake db:migrate
That will ensure that the Rake being invoked is the one you've bundled.

Don't Understand Bundler Interaction with Gems

I thought I understood how Bundler works with gems, but after something that recently happened, I am not sure I have it right.
I am developing an Rails application. To start off (and just so I would get familiar with the Rails environment which I haven't worked in before), I did not use an IDE. But, because I'm missing out on some of the advantages of an IDE, I just started using RubyMine. As part of the RubyMine setup, it asked to update all my gems for my existing project.
After that, I could not run "rake [anything]". Every time I did, I received an error of:
You have already activated rake 0.9.3.beta.1, but your Gemfile
requires rake 0.9.2.2. Using bundle exec may solve this.
I was okay updating to the next version of rake - that wasn't a problem - but I don't understand what happened in the first place. What happened that I "activated" a newer version of rake. Ultimately, I ended up solving the problem by putting
gem 'rake', '0.9.3.beta.1'
in my Gemfile and running
bundle update rake
But, I'm still not sure what happened here. If I was using 9.2.2 before, why did it all of a sudden blow up like that and how can I prevent that in the future?
If you are using Rubymine, you should configure it to run rake tasks with bundle exec.
Go to:
Run -> Edit Configurations -> Defaults -> Rake -> Bundler tab and check "Run the script in context of the bundle (bundle exec)"
Delete all tasks already created and the default will apply the next time you create them again. You can also configure individually each task created.
You should really consider installing and using RVM or Rbenv to manage your ruby versions and gemsets. If you go the Rbenv way, the rbenv-gemset plugin can be used to manage gemsets similar to how RVM natively does.
You have already activated rake 0.9.3.beta.1, but your Gemfile requires rake 0.9.2.2. Using bundle exec may solve this.
At some point between your last bundle execution and installing/configuring/running RubyMine you must have installed rake 0.9.3.beta.1. Because you're not managing your gems through gemsets like RVM or Rbenv will do for you, the default version of Rake became 0.9.3.beta.1 instead of the version installed by bundler, 0.9.2.2.
The above error suggests your Gemfile had something like
gem 'rake', '0.9.2.2'
which does not allow the version of rake being used to be anything but 0.9.2.2.
If you do in fact have 0.9.2.2 on your system in addition to the 0.9.3.beta.1 and your Gemfile is configured for 0.9.2.2, instead of running
rake some:task
you can run
bundle exec rake some:task
and bundler will run some:task through the 0.9.2.2 version of rake. Running tasks related to gems found in a Gemfile through bundleer with bundle exec ... is considered good practice regardless of using RVM or Rbenv.
You can read about bundle exec here.

Should Rake be in the same bin directory as ruby and irb and gem?

I'm new to Ruby on Rails, and I'm setting up Ruby on Rails on my Macbook Pro running Snow Leopard. Everything seems to be going smoothly, but I noticed the following issue.
When I run the which command in the terminal, "Rake" is showing up in a different directory than "ruby", "gem", and "irb". There is also a "rake" executable in the same directory as "ruby", "gem", and "irb", but again, the "which" command returns the "rake" executable below. Should it return the same path as the others? I wonder if this is a problem, and if so, how should I handle it?
My terminal command:
vins-MacBook-Pro:~ $ which ruby gem irb rake
My results:
/Users/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
/Users/.rvm/rubies/ruby-1.9.3-p194/bin/gem
/Users/.rvm/rubies/ruby-1.9.3-p194/bin/irb
/Users/.rvm/gems/ruby-1.9.3-p194#global/bin/rake
It's fine. You're using RVM but the looks of your path. Rake is installed as a gem in the global gemset for 1.9.3-p194. It's pulling the rake executable from the gem's bin directory.

Rake, bundle, rails command not found on rvm

I just installed rvm + rails 3+ on centos 6.0 at Rackspace cloud server. Everything works fine, but sometimes when i ssh to server i can't use rake, bundle or any other rails related commands it always shows me errors like:
bash: rake: command not found
when i try to run bundle install it shows me this error:
ERROR: Gem bundler is not installed, run `gem install bundler` first.
but i do have it installed for sure and it worked before.I can use rvm rake db:migrate - but it used to without rvm prefix...Please help i dont know why is that happening - maybe something wrong with bash profile...
have you used a ruby ?
rvm use 1.9.3
this will select properly environment and make all commands working properly.
to make this setting permanent for new sessions also use:
rvm use 1.9.3 --default

failed rake db:migrate

When i typed: sudo rake db:migrate
I got:
rake aborted !
/home/trace/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end...sion_store :cookie_store, key: '_trace_session'
Note that my version of ruby is:
ruby -v: 1.9.2p312
And that in my bashrc i have:
rvm use 1.9.2-final#rails310.
session_store.rb:
# Be sure to restart your server when you modify this file.
Trace::Application.config.session_store :cookie_store, key: '_trace_session'
Thanks in advance
The problem is that you're using sudo... this is causing the system's Ruby (probably 1.8.7) to be used instead of your rvm Ruby. Just get rid of the sudo and run this:
rake db:migrate
Whenver rvm in used, sudo is skipped unless we need to install system libraries if the gem installation fails which installed in system. All the local gems are used from the gemset or from the global if no gemset is specified.Just have look over a tutorial on web to make things easier in rvm. solution suggested by dylan makes things clear.

Resources