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.
Related
I'm freshly using rvm for running a legacy project.
I installed rvm fine. Running which ruby gives the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Then running which bundle, also indicates that bundle is using the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Now to get my project running, I run bundle install. It's important to stress on the fact that in my Gemfile I have
gem 'rails', '5.0.7'
Running rails s after those steps, gives:
Rails is not currently installed on this system. To get the latest version, simply type:
Running which rails gives:
/usr/bin/rails
implying that the system version and not the rvm version is being used.
echo $PATH shows:
/Users/Mahmoud/.rvm/gems/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/gems/ruby-2.5.5#global/bin:/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/bin:/Users/Mahmoud/.pyenv/versions/3.7.2/bin:/usr/local/bin:/Users/Mahmoud/.pyenv/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin:/Users/Mahmoud/.ebcli-virtual-env/executables:/usr/local/mysql/bin
My question is, why hasn't rails been installed when I used bundle install? And why is which rails refering to my system and not my rbenv path?
I'll bet your RVM isn't set up correctly and /usr/bin/ appears in your PATH before RVM's bin directory. Run echo $PATH to confirm.
If so, back up your dotfiles for safety and run rvm get head --auto and it should put your PATH right. Logout and log back in or source your dotfiles (source ~/.bash_profile or whatever) and try again.
I am trying to install bundler and I get the following error.
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I have poked around on this site and other places and found the common suggestion to install rbenv, which I did using homebrew. I also added Add rbenv init to my shell using the following command:
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
I then started a new shell so that PATH changes take effect then checked if rbenv was set up:
$ type rbenv
#=> "rbenv is a function"
All good so far.
Then I try to install bundler again using the gem install bundler and I still get the error
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I have also been experiencing problems with my Python setup and I suspect this is symptomatic of the same root cause, but I'm not sure what to do next. Any ideas?
I'm running Mac OS X 10.9.1
Try making your directory permissions less restrictive with chmod or Finder > File > Get Info. Also, check that your umask isn't more restrictive than you want.
Definitely avoid changing permissions, especially since rbenv is possibly using the system's ruby. Instead you should have your own ruby, locally, with rbenv. Somewhere rbenv is still using the root owned system's version instead of your local PATH.
OP should be able to install local gems instead of system-wide ones.
See stackoverflow.com/a/23510249/1899424 – dcorking Feb 29 at 10:52
This helped put me in the right direction resolving the same issue you've encountered. Still trying to get snorby.
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.
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