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.
Related
I have installed ruby (2.7.0) using
snap install ruby
before this, I removed ruby 2.3.0 by deleting all its files, after
sudo apt-get remove ruby
but now the gem command just doesn't work. I have reinstalled it, but whenever I use gem, I get this message,
bash: /usr/local/bin/gem: /usr/local/bin/ruby: bad interpreter: No such file or directory
Ruby is currently installed in
/snap/bin/ruby
Your system PATH is determining the wrong direction for gem.
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting. (Wikipedia)
You can fix the problem by finding out which directory is being prioritized using which -a gem, then re-ordering your PATH.
I made a script to achieve this, here: reorderPathForExe.sh
To run this script, just use git clone and chmod +x, then pass the executable you want fixed as the argument to reorderPathForExe.sh (i.e., ./reorderPathForExe.sh gem for you):
git clone https://gist.github.com/f4f83b23386111bedd7f8199949601af.git
cd ./f4f83b23386111bedd7f8199949601af
chmod +x ./reorderPathForExe.sh
./reorderPathForExe.sh gem
you should probably be installing ruby with RVM or rbenv.
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 installed rvm as root to setup an Ubuntu LTS 8.04 as a web hosting server for my rails apps.
rvm is installed in:
/usr/local/rvm
Everything works fine, gems installation included and users are able to use ruby and gem commands.
sudo gem install rails
My problem is that the gems EXECUTABLE DIRECTORY is not included in my PATH and thus I cannot use rails command.
Is there a way to dynamycally include gems executable directory in my PATH?
Can it be done directly through rvm?
I suspect you don't have RVM setup correctly if it's not in your path.
First, If you run:
type rvm | head -1
and it returns anything other "rvm is a function" then you are not loading it correctly in your profiles.
Second, you may want to include global definitions for the users profiles.
In your users' .bashrc or equivalent
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
And then in your /etc/bashrc, add your executable path.
Probably your PATH was overwritten somewhere on the way, you can put that on end of your ~/.bashrc file:
export PATH=/usr/bin:$(echo $GEM_PATH | sed 's/:/\/bin:/g')/bin:$MY_RUBY_HOME/bin:$PATH
it is not pretty but should work
I'm new to OS X and I'm new to Ruby on Rails.
I just installed Ruby and Rails and when going through my first tutorial here's what I got:
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren't both writable.
WARNING: You don't have /Users/sammat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Could someone help me rectify this situation?
Cheers!
Sam
Did this happen when you tried to install a gem? You need to install gems with superuser privileges so you need to use
sudo gem install [gemname]
rather than just
gem install [gemname].
Either use sudo to install the gem, such as sudo gem install rails
Or add the locally installed gem path to your general path by editing ~/.bashrc (I hope, I'm a suse user, not really OS X, but should still be there and the same) and adding export PATH=~/.gem/ruby/1.8/bin:$PATH to the bottom of the .bashrc file.
That should do it unless my brain has failed me once again.
In OSX you must create the file ~/.bash_login and export the $PATH adding into it:
export PATH="$PATH:/Users/sammat/.gem/ruby/1.8/bin"
You can do this through one command:
echo 'export PATH="$PATH:/Users/sammat/.gem/ruby/1.8/bin"' >> ~/.bash_login