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.
Related
I cant install rails with the usual commannd it gets ignored on my mac. However it seems to be installed according to the terminal output.
Answer can be found by typing
sudo gem environment
then
gem environment
and comparing the results. (gem env is a short version of the command)
Ruby gems are installed locally in directory under specific ruby version, which is also installed in user specific folder (not sure bout MAC situation, but that's the case on my Ubuntu).
Please see the difference on my machine (I am using rvm - ruby version manager):
with sudo - INSTALLATION DIRECTORY: /var/lib/gems/2.7.0
without sudo - INSTALLATION DIRECTORY: /home/le-hu/.rvm/gems/ruby-2.7.2
Using sudo in this case causes the gem to install under root user, not your regular user profile, this leads into gem missing while trying to invoke the gem script being logged in as not-root user.
I'm trying to get a Ruby on Rails Web Application running on a server at school, and I need sudo privileges to do so. For this, I also need PostgreSQL installed as well.
I know that after installation, all that I'll need for PostgreSQL is the usr/local/pgsql/bin, usr/local/pgsql/inlcude, usr/local/pgsql/lib, and so on.. but I'm not particularly sure what kind of privileges I'm going to need during installation.
Also, is it possible for me to install Ruby on Rails without any sudo privileges?
The reason that I can't do everything as a root is because its a school server, and giving a student root access isn't particularly something that the server admin should do. She has to edit the /etc/sudoers file and assign me root access to the appropriate folder(s).
I believe if you use Ruby Version Manager you don't need sudo privileges as it just installs everything on your home directory. Also check out this answer: how to install gems without sudo
As for PostgreSQL you could use Homebrew for the install. If you are still having difficulty you should check out the detail PostgreSQL installation guides.
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.
I'm on Ubuntu. I type in sudo gem install rails. This works fine, installs railes and 7 other gems fine. Yet $ rails blog is saying this:
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
Type
gem env
It will give you the installable directory where the bins of the gems are being installed. Something like this:
EXECUTABLE DIRECTORY: /usr/bin
Make sure this directory is in your path.
how did you install rubygems, as an admin, or as a user? if you installed it as a user, it may not have the bin directory in your path.
If I were you, (assuming you installed rubygems into your home folder), I would trash that installation dir (not sure where it defaults to, maybe ~/rubygems? or ~/.rubygems?), then run setup.rb from the rubygems tarball as admin (through sudo) I've done this at least a dozen times on ubuntu, and haven't run into the issue you are hitting.
If that isn't the case, could you please link to the blog post you were following?
Make sure your gem executable path is added to your system path so that the system can find the rails executable.
I know this is an old thread but the same error had me stuck. Make sure you add
source ~/.rvm/scripts/rvm to your .bashrc file
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.