Installing bundler gives me "you don't have write permissions" error - ruby-on-rails

I had used ruby version manager (rvm) to install a new version of ruby. Running the command rvm rubiesshows all the version of rubies that are installed. The list is given below.
rvm rubies
ruby-1.9.3-p551 [ x86_64 ]
ruby-2.1.5 [ x86_64 ]
ruby-2.2.4 [ x86_64 ]
* ruby-2.3.0 [ x86_64 ]
ruby-2.3.1 [ x86_64 ]
# => - current
# =* - current && default
# * - default
I tried to run the command bundle exec rake rb:mgirate and I get the following error.
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'bundler' (>= 0.a) among 5 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=:/nix/.nix-profile/lib/ruby/gems', execute `gem env` for more information
The error states that bundler isn't installed. I ran the command gem install bundle and I get the following error.
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /nix/.nix-profile/lib/ruby/gems directory.
It says that I don't have write permissions. I googled the error and it has something to do with updating ruby and ruby version. The reason why I updated to a new ruby version was because heroku run rake db:seed wasn't seeding data in production. I though it might be due to compatibility issues. Therefore, I decided to update to the new version of ruby. The servers, postgresql and everything else works fine. I can't run bundle because I can't install the gem. Any hep would be greatly appreciated. Thanks!

The problem was fixed by switching to the ruby version 2.3.0 by running the command rvm user 2.3.0. Once that is done you should restart the workspace. The reason for the error was the fact that when you switch ruby version it also changes gem files. Therefore, it wasn't able to recognize the gems.

hey just add "sudo" at the beginning of your command. It will definitely work, because as the error says you don't have write permission. And if you will check the permission of that directory than you will find that only owner has write permission and as sudo takes us to the owner mode from user mode. Hence you will not get this error again. Please let me know if it doesn't works.

Related

Rails: Handling different versions of gems

I have a rails 5.2 application with rvm installed:
=> ruby-2.4.2 [ x86_64 ]
* ruby-2.4.4 [ x86_64 ]
# => - current
# =* - current && default
# * - default
I want to add the ability to take an automated backup of the database, so installed the backup gem. I understand that this shouldn't be added to the GemFile due to some of its dependencies being relatively old, so I used the command gem install backup-v5.0.0.beta2
When I run gem list there are a number of gems which have two version numbers, e.g. open4 (1.3.4, 1.3.0)
I am running into problems when I try to manually trigger the backup routine via backup perform -t db_backup --config-file /Users/<path_to_my_rails_project>/config/Backup/config.rb, which produces the error:
[error] CLI::Error
[error] --- Wrapped Exception ---
[error] Gem::LoadError: You have already activated open4 1.3.0, but your Gemfile requires open4 1.3.4. Prepending `bundle exec` to your command may solve this.
Following the steer in the error message, bundle exec backup perform -t db_backup --config-file /Users/<path_to_my_rails_project>/config/Backup/config.rb produces the error:
/Users/<my_username>/.rvm/gems/ruby-2.4.2/gems/bundler-1.16.6/lib/bundler/rubygems_integration.rb:462:in `block in replace_bin_path': can't find executable backup for gem backup. backup is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
Please could you advise how I should be installing the backup gem and running the task without hitting errors due to different versions of the same gem being installed
Ensure that you haven't version locked the gem like so: gem open4, '~> 1.3.4'
Try bundle update open4 backup. I would try the latest version of the gem as well.
Another option is to ditch this gem and try https://github.com/javan/whenever and just run a simple pg_dump, or not use any gems and add a cron job that creates a pg_dump with the timestamp in the filename.
These issues can be hard to debug, but my approach is to generally start removing gems and letting bundler figure out its dependency tree on its own. The more you define in your Gemfile them more chances bundler will have a version mismatch thus throwing an error like the one you're seeing.

Running rails console suddenly stopped working

All of the sudden, Rails' console stopped working on one of my projects. I keep getting the following error:
rails c
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
Could not find activesupport-4.1.4 in any of the sources
Run `bundle install` to install missing gems.
So I updated Rubygems, with the following two lines (from rubygems.com)
$ gem install rubygems-update # again, might need to be admin/root
$ update_rubygems
and get the following output:
Successfully installed rubygems-update-2.4.4
Parsing documentation for rubygems-update-2.4.4
Done installing documentation for rubygems-update after 0 seconds
1 gem installed
...
RubyGems 2.4.4 installed
Parsing documentation for rubygems-2.4.4
Installing ri documentation for rubygems-2.4.4
=== 2.4.4 / 2014-11-12
Aaaaaand, then I run rails console again, and just get the same error message again.
Thoughts?
This might be the problem only if you use rvm else just ignore it.
Navigate to the root path (where your rails app is located).
type in your command line;
rvm list
You will get something like:
rvm rubies
jruby-1.7.11 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
=* ruby-2.0.0-p451 [ x86_64 ]
ruby-2.1.0 [ x86_64 ]
ruby-2.1.1 [ x86_64 ]
# => - current
# =* - current && default
# * - default
If your default is not the current you have most likely changed it.
Try to change it back and run:
You can change it like so:
rvm use ruby-2.0.0-p451
When you get the right version you can make it permanent.
like so:
rvm --default use ruby-2.0.0-p451
bundle install
again.
Just a shot in the dark, but maybe try:
gem install activesupport -v 4.1.4
Then try and run rails c again.
The message also says to run gem pristine --all which will reinstall all the gems from the cache and recompile all native drivers in the gems.
Updating the Rubygems code doesn't do this so you have to explicitly run the command.

RVM Gemset: Rails is not currently installed on this system

I have latest RVM installed in OX 10.9.
$ rvm rubies
* ruby-1.9.3-p545 [ x86_64 ]
=> ruby-2.1.1 [ x86_64 ]
$ rvm gemset list
gemsets for ruby-2.1.1 (found in /Users/rajveershekhawat/.rvm/gems/ruby-2.1.1)
(default)
global
rails403
rails404
=> rails410
After this i installed rails.
$ gem install rails -v 4.1.0
It got installed. It is also there in correct location within .rvm folder. But when I try using it, system says rails is not installed.
$ rails -v
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 have tried it twice and still unable to figure out what am I am missing. Please help.
Thanks.
This question is similar but is not helping.
Edits:
$ gem list | grep rails
rails (4.1.0)
sprockets-rails (2.1.3)
$ echo $PATH
/Users/rajveershekhawat/.rvm/gems/ruby-2.1.1#rails410/bin:/Users/rajveershekhawat/.rvm/gems/ruby-2.1.1#global/bin:/Users/rajveershekhawat/.rvm/rubies/ruby-2.1.1/bin:/Users/rajveershekhawat/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Update:
Seems like the rails was not properly installed before. I recreated the gemset and tried to intall rails again but got some error. Then I again emptied the gemset and reinstalled rails with sudo. This resolved the issue.
Try to run:
rvm use ruby-2.1.1#rails410
gem list
Can you find Rails here?
Why did you call sudo gem install rails, cant be this the problem, you do not need to use sudo.

Rails bundle - bad interpreter

I've been working on a rails project in sublime text and switched to rubymine. It said that some gems, which are required in the project, are not installed. Well, I tried to install them, but it fails with an error saying that the used ruby version is another than the version specified in the gem file.
When I enter ruby -v, it looked like the same version. I've then tried to reinstall the ruby version (2.0.0) and as that didn't lead to success, I've installed 2.1.0 hoping it would set the correct path and everything.
When I now try to enter bundle, I get the following error:
bash: /Users/user/.rvm/gems/ruby-2.0.0-p353/bin/bundle: /Users/user/.rvm/rubies/ruby-2.1.0/bin/ruby: bad interpreter: No such file or directory
Version 2.1.0 is not even installed anymore.
I've searched for solutions for a long time but nothing really worked in my case. How would you fix this error? As far as I understand I understand the problem and the answers I've read, some kind of link to a path, used by the bundle command, is set wrong?
I'm using rvm for ruby the versions.
ruby -v says `ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.5.0]
rvm listsays
ruby-1.9.2-p320 [ x86_64 ]
ruby-1.9.3-p0 [ x86_64 ]
ruby-1.9.3-p392 [ x86_64 ]
ruby-1.9.3-p448 [ x86_64 ]
ruby-2.0.0-p0 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
=* ruby-2.0.0-p353 [ x86_64 ]
You should run:
gem install bundler
after reinstalling ruby and point of note, your version of ruby should be same as that in the Gemfile
For me the problem was happening because I had installed 2 versions of Ruby, and after deleted one of them. The console was trying to get the deleted version of ruby.
The solution was:
Remove the old version from the environment vars.
Observation: I'm using Windows 10.

Error with Gitlab: Sidekiq; gemfile syntax error

I've been breaking my head over this error for hours now, and still haven't found a fix. When I run sidekiq using sudo -u root -H RAILS_ENV=production script/background_jobs start I'm getting this error in the sidekiq.log:
Gemfile syntax error:
/home/website/git/gitlab/Gemfile:20: syntax error, unexpected ':', expecting $end
gem "mysql2", group: :mysql
I've installed Ruby 2.1.0 and am running CentOS. I've seen other posts with this error, and their problem was that they were running Ruby 1.8, however, I'm running Ruby 2.1.0 and also getting this error.
Any help is greatly appreciated.
EDIT: My gemfile http://pastebin.com/T5z4GZ3a
bundle returns
Your bundle is complete!
Gems in the groups development, test, postgres, puma and aws were not installed.
It was installed into ./vendor/bundle
EDIT2: My background_jobs script http://pastebin.com/kdicTFqk
bundle show bundler returns
2.1.0
/usr/local/rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.2
EDIT3: I think I have found the problem, not sure how to solve it though. I added p RUBY_VERSION as first line of my Gemfile, then I changed every line written like this: group: :mysql to this :group => :mysql (because that is working on older versions).
However, when I run Sidekiq now, this shows up in the sidekiq.log:
"1.8.7"
bundler: command not found: sidekiq
Install missing gem executables with `bundle install`
I am really, really confused now. Here it clearly says my Ruby version is 1.8.7, but that's not right. ruby -v or rvm list rubies only show that Ruby 2.1.0 is installed, and set as default.
Make sure, that when you issue bundle install you have picked up the ruby 2.1.0, just do as follows:
Enter into app's folder, then edit the Gemfile to a few lines, inserting into it p RUBY_VERSION
Issue bundle install, and see the ruby version output, it shell be 2.1.0, and the form of gem "mysql2", group: :mysql should work.
2.1.0
Then add line one-by-one, or group-by-group, issuing the bundle install
So make sure that the Gemfile will be fully restored at the end.
Then you should do a proper setup shell environment in your run script. So if you use the rvm just replace the first line with:
#!/bin/bash -l
Add sourcing to rvm:
source "$HOME/.rvm/scripts/rvm"
Before starting the script, add shell command to set proper version of ruby to 2.1.0
rvm use ruby-2.1.0#global
NOTE: Probably you have to use an other gemset not the global one.

Resources