Whenever I bundle my rails 3.2 gems, it asks me for my password:
Enter your password to install the bundled RubyGems to your system
This gets really annoying, especially when bundling several times in one project. However, when I set the gem directory to world-readable, it always gives me a warning when executing any (!) rails command. This is even more annoying, of course.
How can I turn this off?
# install gem with the specified path
bundle install --path vendor/bundle
Absolutely has to do with the system ruby, not RVM, unless you installed RVM using the Multi-User installation type. If you did that and its still asking you for your password, then you installed as root, strictly against what the listed documentation states, and your general user was not added to the 'rvm' group the installer creates. (NOTE: This is based on the idea that you want a multi-user install, not a single user one. If you want the single user install, not not prefix with sudo when you run the installer.)
Rip out RVM, log out then back in (to ensure a completely fresh reinitialization of the environment), and then rerun the installer command as your regular user, not as root, prefixing with 'sudo' as the documentation instructs.
If you do not have RVM installed, then follow the documentation at https://rvm.io to install either as a single user install, or as a multi-user install. In this case, without RVM installed, what Billy Chan described above is your fix, though I would suggest tightening the rules a bit by figuring out which exact set of commands (gem bin names) you need to run on a regular basis and adding entries for those in the sudoers file (visudo).
Right now the problem reads you trying to use the system ruby which *RVM does NOT control (it simply allows you access to it by setting the proper GEM_PATH, RUBY_* environment variables etc), or your RVM multi-user install was done incorrectly.
This depends on whether you want to install gems under system or under your user. If under your current user, you can simply turn this message and asking off by adjusting bundler configuration.
In your project in file .bundle/config add line
BUNDLE_DISABLE_SHARED_GEMS: '1'
So whole config file can look like
---
BUNDLE_WITHOUT: development:test
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_PATH: /home/youruser/gems/
I had this problem with my rails installation. A quick workaround for this is to skip bundle install during project creation like so:
rails new webapp -B
And then you can do:
cd webapp/
mkdir -p vendor/bundle
bundle install --path vendor/bundle
Hope that helps future queries.
The best method: Use RVM. With RVM, you can just run gem <any command> without adding sudo
If you don't want to use RVM, you can still add sudo before the commands. And you can set to prevent sudo to asking password for all commands by:
$ sudo EDITOR=vim visudo
# or any editor in your system
Then, edit the doc by adding following line
username ALL=(ALL) NOPASSWD: ALL
# Where username must be replaced by your real username in system
I know it may not be that safe, but it's convenient to use on my own machine.
You can use the above two methods all together like me.
Related
After I run rails new myapp, it downloads gems and then at run bundle install, I always get prompted to enter in my system password.
Is there a way to set the password so I don't have to keep entering it in?
Background info
Why do you have to enter the password in the first place? Because by default bundler will install gems in a system wide location, such as /usr/local/lib/ruby/gems/2.2.0/gems/.... These gems can be used by every user on your pc.
Because it is a shared location, it is usually only writeable by root and therefore you have to enter your password to gain root privileges.
Where are your gems stored? Find out by using bundle show <gem> for a specific gem, for example rake, which in my case says:
bundle show rake
/usr/local/lib/ruby/gems/2.2.0/gems/rake-10.4.2
Solution
a) Change owner of directory
Either make this directory writeable for you. But this is no good practise, because system folders should not be writeable for a normal user. In case you are the only user it still might be OK - then you can simply change the owner of this directory to be you:
sudo chown -R `whoami` /usr/local/lib/ruby/gems/
Now you are the owner and can change files inside without the need of any password.
b) Install gems locally inside project dir
Or you can install all gems locally inside your project dir using the --path option of bundler. It is a convention that those gems are normally installed in vendor/bundle, so you use this command (you can use any path you want):
bundle install --path vendor/bundle
(When you do bundle update next time, you can omit the --path option, because it is saved in the .bundle folder of your project.)
You should add the vendor/bundle folder to your .gitignore (or whatever vcs you are using) to not have it checked in.
Since you write inside a directory you own, you do not have to enter a password. The downside of this is that gems will be duplicated in every project folder if you have multiple projects using the same gems. For a multi user system this is the correct way. But if you are the only one using the machine, variant a) definitely helps to save space and install time.
I'm using variant a) on my own development machine and variant b) on the deployment machine.
It seems like a permissions issue. Try chmod a+w /path/to/bundler
I have browsed around but unable to find why rvmsudo is needed for passenger installation.
I am installing passenger with nginx in my server and I'm using RVM. According to the passenger user manual I need to use rvmsudo to install passenger if I have rvm installed.
Whats the difference between using rvmsudo and without using rvmsudo. Is using rvmsudo to system wide install needed despite having rvm installed locally only ? (just use gem install passenger)
Thank You !
sudo grants a command root permissions to the current user to carry a certain activity (given the user is allowed to use sudo). That said, on installing passenger you need root permission to install files at required locations.
One simple thing to do that comes to mind instantly is:
sudo rvm passenger-install-nginx-module
This won't work! Here's the explanation:
However, this won't work at all. sudo will start a new subshell.
That new subshell's environment will be completely different, and
won't contain RVM, nor will it have access to your user's RVM without
trying to hack in RVM's environment variables yourself.
Therefore you are required to use the solution provided by RVM i.e. rvmsudo. It will pass on any environment variables that RVM set up to get you to the correct Ruby along with sudo privileges, which is exactly what you need to install passenger in this example.
I am new to rails and am learning about bundler. I understand that bundle install installs all the gems specified in the gemfile but where does it install them to?
Does it install them on my computer permanently so that they can be used by any future project?
If so doesnt this mean my computer gets filled with random gem versions and gem installs that I needed for one example project but may never use again?
By default, bundle install is going to install at the root level so all users on a computer could have access to the gems. So 'yes' it is permanent (at least not tied to your application, you can remove them whenever you want).
Take a look at the man pages for bundler. In here, you'll notice that you can specify to install to a local directory.
Install your dependencies, even gems that are already installed to your system gems, to a location other than your system's gem
repository. In this case, install them to vendor/bundle.
$ bundle install --path vendor/bundle
Further bundle commands or calls to Bundler.setup or Bundler.require
will remember this location.
This will let you install the gems to a location inside your application. So when you delete the example app, you also delete the associated gems.
Also, if you would like to see where a specific gem is installed (say you want to look at its source code), type bundle show <gemname>. This will spit out the path to that gem.
The short answer is 'yes'. The longer answer is that there are some technologies which will reduce or eliminate the problems associated with this effect.
If you install 'RVM':
https://rvm.io/
this will allow you to install multiple versions of Ruby and create individual 'gemsets'. As you enter the directory that contains your project, the ruby version and gemset settings are automatically picked up and the active Ruby version will change. This way you can keep gems separate between projects - and use several Ruby versions at once, including JRuby and other esoteric versions.
To find out where gems are stored, type:
gem environment
into your command line and look for the INSTALLATION_DIRECTORY entry in the response.
I'm on ubuntu working with rails here What do I get when I try to install gem?
Here it is
$ gem install rails
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /var/lib/gems/2.1.0 directory.
what should I have to do to get it to work?
Normal user accounts generally don't have the ability (often called permissions or privilege) to write to files in the root (starts with "/") directory.
You need to elevate your privilege to that of a superuser, aka the root user. The most common way is to type
sudo [the command you wanted to run]
So type
sudo gem install rails
The system will ask you for your password and if it's your first time running sudo, it will warn you to be careful. :)
Edit: Listen to iceman's comment about using rvm or rbenv instead. Even though using sudo works for this, that does not mean it is the best option.
I'm trying to comprehend the Unix file system on my OSX. I'm following wikipedia Filesystem Hierarchy Standard.
I understand when I install ruby gems I must use the command sudo gem install but if I omit sudo, problems may occur.
Where are gems installed within the file system when I omit sudo?
How can I delete these gems?
A Fun side question: When I enter cd ~/.gem my terminal is directed to .gem user$, When I enter cd ~/ and list folders using the ls command I can't find a .gem folder. Where is the .gem folder? How does this fit into the Filesystem?
Ok, looking over the Ruby Gems documentation http://docs.rubygems.org/read/chapter/3
the default install directory is:
/usr/local/lib/ruby
Ruby gems uses the environment variable GEM_HOME for the install path. You can change this via the export command like so:
$ export GEM_HOME=/home/mygemrepository $ ruby setup.rb —prefix=/home/mystuff
You can uninstall gems with the gem uninstall command:
gem uninstall gemtouninstall
Finally, as I already mentioned files/folders starting with . (such as .bashrc) are hidden from ls by default, so use the ls -a option to see them. You can read more here: http://unixhelp.ed.ac.uk/CGI/man-cgi?ls
Also, sudo is basically saying, "Do this action as if I was the root user," where the root user is essentially like the highest level administrator. It's a common thing to do when installing software via the command line.