Can't Install Bundler, no permissions - ruby-on-rails

Im using Ubuntu 15.10. This is the code I write in the terminal
gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /var/lib/gems/2.1.0 directory.
Why is it trying to install it there? of course it doesn't have permissions to install it in the root directory. If I try the same command like this sudo gem install bundler it works. But it is not supposed to be installed as sudo, it gives me problems when creating a new Rails app. What should I do?

You should probably start by running gem env and look at your default environment.
You can change the default installation directory by exporting a different GEM_HOME:
export GEM_HOME=$HOME/.gem/

Related

When installing a gem in a local project directory, how do I figure out what the proper gem file path should be?

I'm using Ruby 2.6 and Rail 5. I want to install the following gem
$ gem install ffi -v '1.9.18' -- --with-cflags="-Wno-error=implicit-function-declaration"
Fetching ffi-1.9.18.gem
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
but the above attempts to install it in a global location, and I would prefer to have this in my project directory, which I configured using
bundle config set --local path 'vendor/bundle'
Per the documentation, I can add this to my "gem install" command
--local path_to_gem/filename.gem
but my question is what would "path_to_gem/filename.gem" need to be to properly install this ffi gem, or can I just make something up?
Look into using RVM and taking advantage of its gemset feature. Rails projects are not like Node projects where you would have a node_modules directory where all of your dependencies live. Instead, RVM would manage your dependencies locally and keep them separate using gemsets.

Why doesn't gem install bundler work?

I am trying to deploy an application via Github pages, and based on this tutorial that I am watching, I need to install bundler first.
When I type in the command gem install bundler, I get the error:
While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I do not have rbenv downloaded and I don't know how to. I also do not fully understand the concept of gems.
How can I bypass this issue?
Try 'sudo gem install bundler'

Issue creating new Rails App

When I create a new rails app using rails new Test, I am getting the following error.
run bundle install
Your user account isn't allowed to install to the system Rubygems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to Rubygems using sudo.
I have rbenv -v rbenv 0.4.0 and rails -v Rails 4.2.4
How can I fix this so I can create a new rails app without this issue?
Run
bundle install --path=vendor/bundle
That will install the Gems inside the vendor/bundle directory of your project vs the system gems directory. This is a nice way to keep your gems isolated between apps vs polluting your system gems. Just my 2 cents.
Make sure your user belongs to the RVM group
sudo usermod -a -G rvm myUserName
Run gem env. You should see a list of paths like so under GEM PATHS:
/Library/Ruby/Gems/2.0.0
/Users/sam/.gem/ruby/2.0.0
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
Open your ~/.bashrc file and add the paths as follows:
export GEM_HOME=/Library/Ruby/Gems/2.0.0
export PATH=$PATH:$GEM_HOME:/Users/sam/.gem/ruby/2.0.0:/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
Open a new shell and run the gem install rubygems-update.
Everything should run fine now without sudo.
Running:
rails new test
will not work for an application name anyway because it is a reserved rails word. You would want to go with something like testapp

Error during Installing Rails in Ubuntu 10.04

First I installed rvm for multi-user using script
\curl -L https://get.rvm.io | sudo bash -s stable
and I added users to rvm group.
and rvm seems worked fine. so I installed ruby 1.9.3 and set 1.9.3 as default
and now I tried to install rails with command
gem install rails
It seems worked fine, but when fetching json-1.7.6.gem and an error occurs.
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p374/bin/ruby extconf.rb
creating Makefile
make
sh: make: Permission denied
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p374/gems/json-1.7.6 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p374/gems/json-1.7.6/ext/json/ext/generator/gem_make.out
So I thought it would be related with permission, so I tried
sudo gem install rails
but then this error occurs.
sudo: gem: command not found
What should I do?
use sudo as follows..
sudo gem install rails
Updated Answer:
our $PATH variable needs to include the exact path to your Ruby's bin directory. Adding a directory to the PATH does not include it's subfolders. Try adding the bin directory via:
export PATH=$PATH:/home/adam/.gem/ruby/1.8/bin
or if you installed the gem using sudo:
export PATH=$PATH:/usr/lib/ruby/gems/1.8/bin
You might want to add this to your .bashrc file, so that you don't have to set this manually every time your open up a new bash.
you can use rvmsudo to run sudo commands. But you should really be using Gemfiles to install gems using Bundler.

'gem install' and 'sudo gem install'

I've got an issue installing gems on my mac (os 10.6).
I used to be able to run
gem install <gem-name-here>
but after updating something, it could be the version of gem I'm using, but it's unlikely, I now get the error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/bin directory.
On the face of it, it looks like my 'GEM_HOME' isn't set. If so, why has this been unset, and how can I change it back?
Secondly - when I run
gem list
I see all gems - including those in ~/.gem, but when I run:
gem server
I only see gems in /usr/bin... strange huh?
Any help would be great to resolve this - I dont like using sudo to install gems constantly.
Install RVM.
Profit!
It really is that simple. In addition, you will be able to install and easily switch between different Ruby versions and sets of gems with a single command. It will all be installed in ~/.rvm (by default) and you won't need to use sudo to install gems.
Have you tried doing $bundle update after installing the gems that you wanted?
Follow the instructions in this guide:
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
gem install <gem-name-here>
If you were already doing this, completely delete the ~/.gem directory and try again.

Resources