I use Mac OS X and i have some profile and bash_profile. Here are the contents of my file :
cat ~/.profile
PATH=/usr/local/git/bin:$PATH
export PATH
and
cat ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
export M2_HOME=/Users/myName/Tools/apache-maven-3.2.5
export GIT_HOME=/usr/local/git
export PATH=$PATH:$M2_HOME/bin:$GIT_HOME/bin
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
### ADDED FOR SUBLIME SYMLINK
export PATH=/usr/bin/local/bin:$PATH
Here is the content of $PATH :
echo $PATH
/usr/bin/local/bin:/Users/myname/.rbenv/shims:/Users/myname/.rbenv/shims:/usr/local/heroku/bin:/usr/local/git/bin:/usr/local/git/bin:/usr/local/git/bin:/Users/myname/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-3.4.0/lib/rspec.rb:/usr/bin/local/bin:/Users/myname/.rbenv/shims:/Users/myname/.rbenv/shims:/usr/local/heroku/bin:/usr/local/git/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/ImageMagick/bin:/Users/myname/Tools/apache-maven-3.2.5/bin:/usr/local/git/bin:/usr/local/mysql/bin:/Users/myname/Tools/apache-maven-3.2.5/bin:/usr/local/git/bin:/usr/local/mysql/bin
I don't understand why i have this /Users/myname/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-3.4.0/lib/rspec.rb in the path. How i could remove it ? I cannot see it neither in ~/.profile nor in ~/.bash_profile.
Thanks for your help
That's a binstub for RSpec being set by rbenv.
use rbenv rehash to make sure your .rbenv/versions/... folder is current
Make sure you're using ruby 2.2.2 via rbenv by running rbenv shell 2.2.2
gem uninstall -a rspec
rbenv rehash
Reload shell.
You should only have one of this line:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
You've also got a ton of duplication in your $PATH it's likely your bashrc files are being loaded multiple times, or that you're running another RC script you're not aware of:
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-3.4.0/lib/rspec.rb
/Users/myname/Tools/apache-maven-3.2.5/bin
/Users/myname/Tools/apache-maven-3.2.5/bin
/bin
/opt/ImageMagick/bin
/sbin
/usr/bin
/usr/bin/local/bin
/usr/bin/local/bin
/usr/local/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/heroku/bin
/usr/local/heroku/bin
/usr/local/mysql/bin
/usr/local/mysql/bin
/usr/sbin
See also:
https://github.com/rbenv/rbenv/wiki/Understanding-binstubs
http://dan.carley.co/blog/2012/02/07/rbenv-and-bundler/
Related
I read a few Stack Overflow posts on a similar question, however, I cannot seem to fix my issue.
How do I get ruby --version to match the rbenv version?
rbenv version
2.6.5 (set by /Users/user/rubyonrails/lists/.ruby-version)
ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
When I run
rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
I read a few other questions on Stack Overflow and modified my bash_profile accordingly, however it has not remedied the faulty rbenv init command.
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export PROJECT_HOME=$HOME/Django
source /usr/local/bin/virtualenvwrapper.sh
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/bin:$PATH"
Only add these lines on your .bashrc
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
later use this command $ rbenv install version-ruby
and for switch use $ rbenv global version-ruby
(replace version-ruby for the number of the version.)
When switching from bash to zsh, I looked up how to resolve an issue with my rbenv folder not being used correctly by zsh and found this:
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL
I ran all of these and seem to be using the correct rbenv folder now, but I get this error message whenever I open a new iTerm window:
/Users/myname/.zshenv:2: command not found: rbenv
What am I doing wrong? Any help would be very appreciated.
You need to add two things to your PATH.
First rbenv itself and second the ruby shims.
Part 1 rbenv
Installation
Homebrew
If you installed rbenv with brew,
then the rbenv executable should be linked to /usr/local/bin/rbenv.
See homebrew installation documentation for details.
Please add /usr/local/bin to your path PATH, if it is missing.
# in ~/.zshrc
export PATH=/usr/local/bin:$PATH
Github Checkout
If you install rbenv via a Github checkout, then the rbenv executalbe should be stored in ~/.rbenv/bin.
See github installation documentation for details.
Please add ~/.rbenv/bin to your path PATH, if it is missing.
# in ~/.zshrc
export PATH=$HOME/.rbenv/bin:$PATH
Verfiy
Please verify that rbenv is in your path by calling which rbenv.
The installation path should be returend.
Part 2 shims
Add the ruby shims to you path.
# in ~/.zshrc
eval "$(rbenv init -)"
Instead of the eval "$(rbenv init -)" command you can also add the shims folder directly.
# in ~/.zshrc
export RBENV_ROOT=$HOME/.rbenv
export PATH=$RBENV_ROOT/shims:/versions:$PATH
Part 3 rbenv doctor
You might also run the rbenv-doctor script mentioned here,
to check your installation.
I had the same problem...
when I ran ruby or rbenv, I got this error "command not found"
try this:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
echo 'eval "$(rbenv init - zsh)"' >> ~/.zshenv
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.zshenv
I had this same error. I could run which rbenv and rbenv just fine, but no matter what I would get command not found: rbenv. The issue was that I had eval "$(rbenv init -)" in my ~/.zshenv and not my ~/.zshrc file. You may still have the path to rbenv be added to $PATH within ~/.zshenv for it to work.
I'm trying to install ruby in terminal via homebrew.
So far I've entered:
brew install rbenv
and then I rain
rbenv init
after the command was run I received
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
finally I entered:
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
I restarted my terminal per instructions and then received
rbenv: no such command `init-'
at the top of my new terminal.
error messages: rbenv: no such command `init-'
expected messages: nothing, blank terminal
The default shell (Bash before macOS 10.15) on macOS is a login shell. Only .bash_profile is used in initialization by default.
You need to put eval "$(rbenv init -)" into ~/.bash_profile but not ~/.bashrc.
Bash init files
login mode:
/etc/profile
~/.bash_profile, ~/.bash_login, ~/.profile (only first one that exists)
interactive non-login:
/etc/bash.bashrc (some Linux; not on Mac OS X)
~/.bashrc
non-interactive:
source file in $BASH_ENV
Check the path of the red line for an interactive, login shell on macOS.
References
Unix shell initialization
Shell startup scripts
Long story made short, I am trying to issue myself an SSL certificate using LetsEncrypt, and have recently installed rbenv to make this process easier. After installing rbenv, I check to see if everything checks out using
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
I than get this message saying that there are no versions of ruby installed. After trying to install ruby using the command
"rbenv install 2.3.1"
I get this error
rbenv: no such command `install'
Is it because the path to my rbenv shims aren't in my PATH variable ? If this is the case how do I add directories to my PATH variable ? I know you have to add them to your bash_profile file, but am not sure where in this file I need to add something, and what I need to add.
~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
function letsencrypt_webfaction {
PATH=$PATH:$GEM_HOME/bin GEM_HOME=$HOME/.letsencrypt_webfaction/gems RUBYLIB=$GEM_HOME/lib ruby2.2 $HOME/.letsencrypt_webfaction/gems/bin/letsencrypt_webfaction $*
}
eval "$(rbenv init -)"
PATH=$PATH:$HOME/bin
export PATH
export PATH="$HOME/.rbenv/bin:$PATH"
Always be careful when editing the profile.
Better make a backup first
switch to home directory:
cd
list hiden files:
ls -la .bash*
make a backup copy of .bash_profile:
cp -p .bash_profile .bash_profile.bak
check the current PATH: echo $PATH
check if ruby is in the PATH: which ruby
check the ruby version: ruby --version
I am not sure where this function is comming from in your .bash_profile: function letsencrypt_webfaction()
Use : as a separator and add a new directory new_dir to your PATH, use $PATH to keep the contents of the actual PATH, then export the new PATH:
PATH=$PATH:/new_dir:/new_lib
export PATH
Verify if the PATH is what you need from the terminal: echo $PATH
Personaly I sugest making a backup of .bash_profile as it is. Comment out with # the 3 lines for the function and the others where the PATH appears and add this:
export RUBYLIB=$HOME/lib
export GEM_HOME=$HOME/gems
export PATH=$HOME/bin:$PATH:
After this please check the bulet points above and see if you have the ruby version you expect.
According to the documentation you should install the ruby-build plugin:
The rbenv install command doesn't ship with rbenv out of the box,
but is provided by the ruby-build project.
rbenv installed. but rbenv shell not command.
ationtekiMacBook-Air:~ dation$ rbenv versions
system
* 2.0.0-p247 (set by /Users/dation/.ruby-version)
dationtekiMacBook-Air:~ dation$ rbenv version
2.0.0-p247 (set by /Users/dation/.ruby-version)
dationtekiMacBook-Air:~ dation$ rbenv shell
rbenv: no such command `shell'
ationtekiMacBook-Air:~ dation$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
There is this note in rbenv's README (see Installation) about the shell command:
Note that you'll need rbenv's shell integration enabled (step 3 of the installation instructions) in order to use this command.
Step 3 is:
Add rbenv init to your shell to enable shims and autocompletion.
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Same as in previous step, use ~/.profile on Ubuntu, ~/.zshrc for Zsh.
Did you follow that instruction?
one gotya that I haven't seen posted on the internet is that in .bash_profile, you have ensure that
export PATH="$HOME/.rbenv/bin:$PATH"
is placed before
eval "$(rbenv init -)"
Otherwise the shell will try to run rbenv init before it can be found.
Reversing these two lines will cause both problems described by the OP;
ruby -v not showing the version that was set by rbenv
rbvenv shell returning "rbenv: no such command `shell’".
Don't ask how I know!
I today opened an issue in Github to propose an update to sstephenson's already awesome documentation.