Can't run Rails server because of json gem error - ruby-on-rails

I get an error while trying to run the rails server. Seems like I can't install the json gem properly. When I first tried to install the gems, I got the 1.8.2 version of the json gem. For some reason I got the same error messages as attached when I tried to run the server. In order to install the 1.7.7 version of json, I have uninstalled the 1.8.2 gem.
Does anyone know how to fix this problem? Thank you in advance:)
$ rails s
Could not find json-1.7.7 in any of the sources
Run `bundle install` to install missing gems.
$ bundle install
Fetching gem metadata from https://rubygems.org/........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Using rake 10.0.3
[...]
Using rack-ssl 1.3.3
Errno::EACCES: Permission denied # rb_sysopen - /Users/annemarit/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/json-1.7.7/.gitignore
An error occurred while installing json (1.7.7), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.7'` succeeds before bundling.
$ gem install json -v '1.7.7'
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/annemarit/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/json-1.7.7/.gitignore

When permission is denied, this can sometimes mean that you installed the gem with sudo permission meaning that you have to have root access to install/update. This happened once to me where I was installing everything with root access since I was signed in as root and forgot.
The solution I found was to uninstall everything and reinstall as non sudo. It was a painful process, but it fixed my no permission error. If you continue as root and keep installing everything as sudo, you will run into major problems later as well, so never run in sudo when developing RoR applications.
I hope this helps!

Related

bundle install failing with error Zlib::DataError: invalid distance too far back

I am running bundle install command by going into my docker container and i am getting below error
root#internal:/srv/deviceservice# bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Fetching source index from https://gems.contribsys.com/
Fetching source index from https://gems.contribsys.com/
Fetching gem metadata from https://rubygems.org/..........
Fetching source index from https://rubygems.org/
Resolving dependencies................
RubyGems 1.8.23 is not threadsafe, so your gems will be installed one at a time. Upgrade to RubyGems 2.1.0 or higher to enable parallel gem installation.
Fetching rake 10.4.2
Zlib::DataError: invalid distance too far back
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that `gem install rake -v '10.4.2'` succeeds before bundling.
In Gemfile:
coffee-rails was resolved to 3.2.2, which depends on
railties was resolved to 3.2.21, which depends on
rake
root#internal:/srv/deviceservice# gem install rake -v '10.4.2'
ERROR: While executing gem ... (Zlib::DataError)
invalid distance too far back
root#internal:/srv/deviceservice#
My ruby version is 1.9.3 and rails version is '3.2.21' . i was not able to find anything related to this issue on the internet. any idea what this error is coming ?
It means the data is corrupted. Either in transit or at the source.

How to fix permissions error when installing Rails on Windows

I have Ruby 2.2.6 and Rails 5.0 installed succesfully, however I don't seem to be able to install gems. Here's the error I get:
Errno::EACCES: Permission denied # rb_sysopen -
C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/nokogiri-1.7.1-x86- mingw32/lib/nokogiri/2.3/nokogiri.so
An error occurred while installing nokogiri (1.7.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.7.1'` succeeds before bundling.
I searched for solutions but all the suggestions are for Unix commands.
I'm on Windows so I'm not sure how to enable permissions in order for this install to pass succesfully.
Any (ELI5 level) suggestions for me?
Have you tried executing:
gem install nokogiri -v '1.7.1'
In your command line?
If you are still getting an error, post the error message.
If you go to the Nokogiri website, you'll find special instructions for installing it on Windows.
A number of Ruby libraries are called native libraries, meaning they're written in C for Unix, and so require Unix build tools to make.

Bundler cannot load gem rake

I'm currently SSH'd into a remote server where I am trying bundle install, but here is the message that it spits out when I run it:
Fetching gem metadata from http://rubygems.org/...........
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies...
sudo: effective uid is not 0, is sudo installed setuid root?
Gem::Exception: Cannot load gem at [/usr/lib64/ruby/gems/1.9.3/cache/rake-12.0.0.gem] in /home2/shsprogr/rails/Frothy-Fox
An error occurred while installing rake (12.0.0), and Bundler cannot continue.
Make sure that `gem install rake -v '12.0.0'` succeeds before bundling.
And yet, when I run gem install rake -v '12.0.0':
Successfully installed rake-12.0.0
1 gem installed
Installing ri documentation for rake-12.0.0...
Installing RDoc documentation for rake-12.0.0...
Yet the same thing happens with bundler above. If it helps, I'm on a bluehost server and I am unable to enable sudo access because this guide is out of date.
You're likely going to find several things with Bluehost rails a challenging affair. You might consider creating a free developer account on Heroku instead. It will make this process a little easier.
However, you can fix your issue by setting a GEM_HOME in your htaccess file. This is going to make sure that gems are installed in your web directory of the shared bluehost server - so they won't run into the kinds of issues that require sudo. So open your .httacess file in your favorite editor and add this line:
SetEnv GEM_HOME /home2/shsprogr/ruby/gems

ruby on rails gem file installation install bundle

I am new with ruby on rails. I have successfully installed ruby on rails 4.2 on Ubuntu 14.04 and created a new app, but when I started the server to see if it is working by writing:
rails server
I get this error message:
Could not find gem 'sass-rails (~> 5.0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
And when I start to install bundle I get other packages that need to be installed before bundle.
Error message for bundle install
Gem::RemoteFetcher::FetchError: Errno::EHOSTUNREACH: No route to host - connect(2) for "rubygems.global.ssl.fastly.net" port 443 (https://rubygems.org/gems/minitest-5.5.1.gem)
An error occurred while installing minitest (5.5.1), and Bundler cannot
continue.
Make sure that `gem install minitest -v '5.5.1'` succeeds before bundling.
then after I installed minitest and run bundle install
I got this error message
Gem::RemoteFetcher::FetchError: Errno::EHOSTUNREACH: No route to host - connect(2) for "rubygems.global.ssl.fastly.net" port 443 (https://rubygems.org/gems/debug_inspector-0.0.2.gem)
An error occurred while installing debug_inspector (0.0.2), and Bundler cannot
continue.
Make sure that `gem install debug_inspector -v '0.0.2'` succeeds before
bundling.
It keeps showing me packages that I need to install before bundle.
I'm not on Ubuntu, but I find with Rails 4+ this step-wise gem install is the rule rather than the exception. It doesn't seem to handle dependency gem installs very well with bundle. For each of the "missing" dependency gems, run the single gem install, and then the bundle again to see what's next It may reveal another dependency with each step, just install that. (The caveat is if you're seeing the same gems show up as not being installed on every bundle exec, then that's another problem altogether. Once you single-install the gem it should be locked in and available)
$gem install bundle
$gem install name-of-flagged-gem
$gem install bundle
$gem install next-missing-gem
Hope this helps.
Your solution should be right here: SSL Error
I had the same exact problem. Each time I did a "bundle install" it told me to make sure "gem install .... succeeds before bundling" And when I did what it said, it just told me about another gem.

issues deploying Rails site

I am attempting to deploy a site on a commercial hosting service. (JustHost.com)
I am having the following issue running bundle
# bundle
Fetching gem metadata from https://rubygems.org/........
Fetching gem metadata from https://rubygems.org/..
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
Gem::Exception: Cannot load gem at [/usr/lib64/ruby/gems/1.9.3/cache/rake-10.3.0.gem] in /home5/<username>/<sitename>
An error occurred while installing rake (10.3.0), and Bundler cannot continue.
Make sure that `gem install rake -v '10.3.0'` succeeds before bundling.
I am able to successfully run the gem install command:
# gem install rake -v '10.3.0'
Successfully installed rake-10.3.0
1 gem installed
Installing ri documentation for rake-10.3.0...
Installing RDoc documentation for rake-10.3.0...
But I get the same error re-running bundle. Furthermore, I don't think I was actually able to install rake - its location is not writable by me and the version is unchanged:
# which rake
/usr/bin/rake
# rake --version
rake, version 0.9.2.2
I also tried updating my Gemfile to use rake 0.9.2.2. but ran into the same issue:
# bundle
Fetching gem metadata from https://rubygems.org/........
Fetching gem metadata from https://rubygems.org/..
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
Gem::Exception: Cannot load gem at [/usr/lib64/ruby/gems/1.9.3/cache/rake-0.9.2.2.gem] in /home5/<username>/<sitename>
An error occurred while installing rake (0.9.2.2), and Bundler cannot continue.
Make sure that `gem install rake -v '0.9.2.2'` succeeds before bundling.
Any help appreciated!
What I did to get around this was update the .bashrc file per the instructions here. I also had to setup a javascript runtime so I used gems rubyracer with execjs.

Resources