"You don't have [PATH ]in your PATH, gem executables will not run." while using "gem install --user-install bundler" - ruby

I was trying to install jekyll in my Mac and got the warning as following:
WARNING: You don't have /Users/Carrot/.gem/ruby/2.3.0/bin in
your PATH, gem executables will not run.
I checked through gem list and it shows it is installed; and I can find the jekyll through the path "/Users/Carrot/.gem/ruby/2.3.0/bin". I read a post which seems like my situation. I would like to know if it's a must to go through sudo? I now prefer to uninstall everything (since it also installed sass and bunch of things at the same time) and go through homebrew. How can I do the uninstallation?
Many thanks!

For those who have problems with #lamech-desai answer, (actually, when they do Desai's commands, it apparently works temporarily for them).
So you can easily do these:
open ~/.bshrc if you would like to use bash or ~/.zshrc if your are using zsh or etc...
$ sudo nano .bashrc ## bash users
$ sudo nano .zshrc ## zsh users
then copy and past these two lines of code at the end of the .*rc file:
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"
then simply press ctrl+s and ctrl+x. This will save the changes to .bashrc but you won't see them immediately - directly on your next shell login with your current user. One way to see the changes immediately is to switch user to root with su root and then switch back to your previous user with su <username> - and voila, your .bashrc will be reloaded. You can also check this with echo $PATH.
Thanks to #lamech-desai for great answer

If you are using arch linux just use the commands below in your terminal
[user~]$ export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
[user~]$ export PATH="$PATH:$GEM_HOME/bin"
[user~]$ gem list
[user~]$ gem update

You need to add the directory to your PATH environment variable
https://askubuntu.com/questions/406643/warning-you-dont-have-a-directory-in-your-path-gem-executables-will-not-run

If you are on a Mac like me, you need to add the PATH to the PATH environmental variable. You can do it with export command:
export PATH="/Users/Carrot/.gem/ruby/2.3.0/bin:$PATH"
If you wanna know more about this process, here is a blog post about this: Adding a Path to the Linux PATH Variable

Probably a bit odd to answer my own question but I did finally fix it somehow like a blind fly. I hope to write down the experience maybe who else is totally like me as a absolute beginner with everything wouldn't get struggling overnight.
Stage 1: from gem to homebrew (failed)
At the beginning, I did remove items that install in gem item-by-item, then I install brew-gem to do it. At some stage, it work for jekyll but not my theme. It kept popping out I didn't install a package that the theme needs even I installed it manually. So in the end, I remove everything related to jekyll from homebrew.
Stage 2: back to gem (very long path but finally made it)
I later found a page tell step-by-step to install jekyll. I am using OSX 10.13 (High Sierra) that cause me the permission problem. So I just granted access with this line:
sudo chown -R $(whoami) /usr/local/*
The * is a must or it won't work. I did the same to the ruby part
sudo chown -R $(whoami) /Library/Ruby/Gems/2.3.0/*
After that I install jekyll and bundler carefully following the instruction. And install the packages that the theme needs manually through gem install, which you can find at the Gemfile. I got the problem of jekyll-sitemap similar as this, I followed the method to install pygment.rb through gem install pygments.rb. And now my site is locally work.

Related

Installed gems are not running

I am trying to install jekyll.
I run gem install bundler jekyll
After installing gems I run bundle init and get
bash: bundle: command not found
How can I fix it?
You can get a gem's directory using gem which. For example:
$ gem which jekyll
/home/username/.rvm/gems/ruby-2.6.4/gems/jekyll-4.0.0/lib/jekyll.rb
Then append the directory to your PATH:
$ export PATH="$PATH:/home/username/.rvm/gems/ruby-2.6.4:"
The reason why you are getting "command not found" after installing gems is because they were installed in a location that your bash shell does not yet know about. The way the computer looks up commands is by looking at the PATH, which is a list of folders where the computer should look for commands, such as bundle. The previous answer is on the right track, but unfortunately, the gem which command will only tell you about locations that are already in your PATH, which might not include the folder where bundler and jekyll were installed.
The location of the gems depends on how you installed Ruby, so without knowing that, I can't tell you what to put in your PATH. What I can tell you is that what you are experiencing is unfortunately very common, but there is a fix. To avoid needless frustration and to help people like you, I wrote a script that will automatically set up a proper Ruby environment for you, including updating your PATH and everything else that is necessary to be able to install gems and use them right away without getting any errors. Check out the links at the bottom of this answer to learn more about my script.
In the meantime, I can make some guesses and see if I can help. If you installed Ruby with Homebrew, then this should fix it:
Run this command:
echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"' >> ~/.bash_profile
And then quit and restart your terminal. Now you should be able to run bundle init.
If you are reading this and you are not the original poster, you might need to replace .bash_profile in the command above with .zshrc depending on which shell you are using. You can tell by looking at the error. If you are using zsh, it will say zsh: bundle: command not found.
You can read more about my script and other ways to fix the "command not found" error in these articles:
https://www.moncefbelyamani.com/troubleshooting-command-not-found-in-the-terminal/
https://www.moncefbelyamani.com/how-to-install-jekyll-on-a-mac-the-easy-way/
https://www.moncefbelyamani.com/the-definitive-guide-to-installing-ruby-gems-on-a-mac/

How to install ruby system-wide using rbenv

You may think this is a classic "global" command question, but it is not.
I can set ruby globally by this:
rbenv global 2.5.1
However this makes ruby2.5.1 global for all users but not for the whole system. When an application in same server want to call ruby or access/pipe ruby, they get command not found error.
I believe we should have to install or symlink to /usr/bin or /usr/local/bin or something...
I couldn't find anything regarding to this. How can I make selected ruby version to be seen to other applications?
My only solution is to build ruby myself to system dir but this will conflict with rbenv.
Examples:
When postfix want to pipe an email to ruby it cannot find ruby even i set global.
When webmin trying to run a command via ruby it cannot find ruby too.
Workaround:
Adding /root/.rbenv/shims folder to the $PATH on executed script works as expected but in some cases it is not possible to directly modify $PATH. What is my option here?
rbenv is simply not designed to do support this, you can see the discussion surrounding this within this Github Issue. There are many technical considerations to take into account like permissions if you do this. I found another blog post outlining the process - System Wide Install With rbenv. Going to copy it into this answer incase the blog post goes away.
However, in the long run, you may find that it's simply easier to create or use Ruby packages, such as the BrightBox PPA ones.
Installing rbenv
Instead of the usual location of ~/.rbenv for single installs we'll
be installing to /usr/local. You can use a different path if you
want, but this is what I prefer.
cd /usr/local
git clone git://github.com/sstephenson/rbenv.git rbenv
chgrp -R staff rbenv
chmod -R g+rwxXs rbenv
Make sure the users that will use rbenv are part of the group you
associated with the rbenv folder.
Now we want to add the following code into each users ~/.profile,
~/.bash_profile, or ~/.zshenv depending on the environment. You
can also add it in /etc/skel/.profile or /etc/skel/.bash_profile
template files that are copied when new users are created.
export RBENV_ROOT=/usr/local/rbenv
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
Installing ruby-build (optional)
Optionally, you can install the ruby-build plugin to save yourself
from building it yourself.
cd /usr/local/rbenv
mkdir plugins
cd plugins
git clone git://github.com/sstephenson/ruby-build.git
chgrp -R staff ruby-build
chmod -R g+rwxs ruby-build
Notes
Now you should have rbenv and optionally ruby-build setup so you can
get started installing and using Ruby. This install is the same as the
single user install with two exceptions. The global setting applies to
all users and single user rbenv installs can "override" the system
wide install.
If you have permission issues make sure all the files in the rbenv
folder belong to the proper group and that the users trying to use
rbenv are also members of the group.

Using rbenv doesn't work with sudo?

Any commands that use sudo don't seem to work with RBenv.
I'm trying to install ActiveRecord and it says I don't have write permission, so when I try this:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/local/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1 directory.
It says:
sudo: gem: command not found
How can I get around this?
The idea behind tools like rbenv and RVM is that you don't need to use sudo, because your entire Ruby environment exists inside your own workspace as a sandbox.
RVM allows multi-user configurations though it was originally designed for single users.
As far as I've ever seen or read, rbenv is single-user only. At no time should you need to use sudo to manipulate or change your Ruby environment when using rbenv. If you do, something is wrong. If you try to use sudo, you'll screw things up. You might not find out immediately but eventually something will pop up and you'll need to change the ownership of the files back to you.
On Linux and Mac OS you can do that pretty easily using:
sudo chown -R <your_user_name>:<your_group> ~/.rbenv
You have to run that as sudo because only the super-user can change ownership of files owned by root. sudo escalates your privileges to allow you to change those things.
I realise this is kind of old now, but this may help people in future:
rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.
https://github.com/dcarley/rbenv-sudo
My answer in "Installing Ruby 2.0 and Rails 4.0.0beta on AWS EC2" might be useful to you.
In short, the root user needs to have rbenv loaded in its environment for you to use the gems installed by rbenv. This can be done by adding the following
# /etc/profile.d/rbenv.sh
export RBENV_ROOT=/usr/local/rbenv
export PATH="${RBENV_ROOT}/bin:$PATH"
eval "$(rbenv init -)"
This should be sufficient for sudo to work. If you are writing a shell script, you might need to use
. /etc/profile.d/rbenv.sh
before using executables from other gems.
My answer is a little bit late but I have simple solution for this issue. Use symbolic links to be able use binstubs and other Ruby stuff.
ln -s ~/.rbenv/bin/rbenv /usr/local/bin/rbenv
ln -s ~/.rbenv/shims/* /usr/local/bin
I hope that helps to other users who is having the same issue.

Linux Install RVM without using CURL

My current environment (including a corporate proxy) is not allowing me to install RVM with CURL or WGET for something reason. Is there another way to install RVM from source without these utilities? Every web search I've done returns the 'curl' way.
Any ideas?
modifying rvm scripts is not a good idea
I was thinking about your question/my answer while trying to sleep... and I couldn't get an eye closed without writing you another answer. Hacking the rvm install script is really not what you should do. Rvm uses curl everywhere (installation, downloading rubies, updating, ...). And you have to download many more things -- for example gems. Replacing every curl-call in every script is not maintainable.
proposed solution
The good thing about rvm is, that is stores all its data in the ~/.rvm directory. Considering this, you can install rvm on a remote computer (or VM), which is as similar as possible (same OS, same OS version, same libraries) to your development computer. Install all the rubies, gemsets and gems you need. Then move the zipped ~/.rvm directory to your development computer and unpack it to ~/.rvm.
Don't forget to do
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
to source rvm while loading your bash.
If you ever have to update or install gems or ruby versions, do your business on the remote computer, and copy ~/.rvm again.
my experience with this setup
I use this setup (although it is automated with our CI server) for ¬2 years now for a production environment which is in a similar wicked corporate network. Changing gems/rubies is harder than it should be, but it works without an internet connection.
Edit: Added a paragraph about my experience with this setup
You find the rvm install script here. You can
download it
modify the parts where curl is used
execute the script, which now refers to the manually downloaded files
1. Download
Download this file to /tmp/rvm-installer .
Now download the rvm.tar.gz file to /tmp/rvm-1.19.6.tar.gz
2. modify the file
At line 148 begins function fetch_version. Replace it with the following function:
fetch_version()
{
echo '1.19.6' # the current version, as of writing this
}
At line 161 (within install_release) the get_and_unpack function is called.
replace the function call with:
get_and_unpack \
/tmp/rvm-${_version}.tar.gz \
rvm-${_version}.tar.gz
At line 212 (within get_and_unpack) replace
__rvm_curl ${_url} -o ${rvm_archives_path}/${_file} ||
with:
mv ${_url} ${rvm_archives_path}/${_file} ||
3. finally install rvm
cd /tmp
cat rvm-installer | bash -s -- --version latest --autolibs=enabled
Disclaimer: This is still a hack. It installs rvm, but I don't know about updating (here rvm uses curl again). Good luck :)

rvm install on rhel6

ok, so i'm coming from a python virtualenv environment, so please bear with me...
i am trying to install rvm on a non-internet visible machine (ie it doesn't have direct outside access). so
curl -L https://get.rvm.io | bash -s stable --ruby
would not work. no problems i thought, i'll just copy the file over from another machine and do a cat that worked, however, because rvm tries to download the source files directly from the web, it again failed....
so i found that if i put the tarballs under ~/.rvm/archives, i can install rvm as a single user (and take up ~200MB of my home space)... however, i want to install for multiuser for production purposes and use .rvm directories in my project. however, my /usr/local is read only (afs mount).... so rvm fails again.
any ideas? i don't particularly like the idea of having a rvm user and group.
I believe you can supply --path=/opt/rvm to the RVM install script to change the location of a multi-user installation.
I don't believe the RVM group can be changed as it relies on that group to operate correctly.
hmm... so i decided to look at the rvm-install script (ie https://get.rvm.io). basically, it was hardcoded to /usr/local/rvm, so i just changed that to /opt/rvm.
i then also had to add a check for the rvm tarball under the get_and_unpack function:
if [ -e ${rvm_archives_path}/${_file} ]
then
true
elif curl -L ${_url} -o ${rvm_archives_path}/${_file}
then download the file at https://github.com/wayneeseguin/rvm/tarball/master into /opt/rvm/archives/wayneeseguin-rvm-master.tgz
that installed rvm fine into /opt/rvm.
however, logging back in will result in -bash: __rvm_add_to_path: command not found. this is because the profile.d script is hard coded to /usr/local/, so doing a find and replace on /etc/profile.d/rvm.sh to /opt/ did the trick.
however, all the files are still group'd to rvm. which is fine, but another group i have to justify to my unix-admin.

Resources