.zshenv:2: command not found: rbenv error - ruby

ive been trying to load ruby on my macOs Big Sur and i cannot for the life of me figure out how to fix this
i was trying to install cocoapods when it gave me this error so i follwed this instruction and im now getting this error \
/Users/kashish/.zshrc:103: command not found: rbenv
➜ ~ export PATH=/usr/local/bin:$PATH
➜ ~ which rbenv
rbenv not found
➜ ~ export PATH=/usr/local/bin:$PATH
➜ ~ rbenv doctor
zsh: command not found: rbenv
➜ ~ 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
➜ ~ rbenv doctor
zsh: command not found: rbenv

Related

Command Brew not Found?

I installed homebrew with ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" on Mac but when I try to install python3 with
brew install python3
I get error of
zsh: command not found: brew
I know brew is installed but maybe I haven't done it in right location? I am in a directory of a folder in my desktop
Output of echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Thanks for the help in advance
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/neerajvishwa/.zprofile
type this in terminal - it worked for me
If using Macbook M1 chip run this after installation done
eval $(/opt/homebrew/bin/brew shellenv)
I use the MacBook Air M1 and I have the same issue, where I need to run eval $(/opt/homebrew/bin/brew shellenv) every time I open the terminal to use brew.
I reran the 2 commands we are supposed to run after installing homebrew. (You need to replace [username] by your Mac user name)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
I even completely rebooted my Mac to make sure the fix was permanent.

Why do I get: 'ERROR: While executing gem ... (Gem::FilePermissionError)' when trying bundle install?

I am trying to run 'gem install bundler' on a new macbook pro.
I get :
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
I have tried using RVM
I have tried using RBENV
rbenv doctor gives this output:
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20190423)
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK
My bash profile is like this:
alias brewup='brew update; brew upgrade; brew cleanup; brew doctor'
###
## Colors and prompt customisation
## OLD: export> PS1="\[\033[36m\]\u\[\033[m\]#\[\033[32m\]\h:\[\033[33;1m\] \w\[\033[m\] \$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1=" \[\033[01;35m\]\u#\h: \[\033[01;32m\]\w \[\033[01;34m\]\$(parse_git_branch) \[\033[01;34m\]\n>\[\e[0m\]"
## NVM stuff
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
## Ruby rbenv stuff
eval "$(rbenv init -)"
export PATH="/usr/local/sbin:$PATH"
export PATH="/Users/georgeclark/.gem/ruby/2.3.7/bin:$PATH"
the last 3 lines are vague attempts at getting this working, could well be wrong.
The output from some terminal commands I ran are as follows:
If I do ruby -v
I get: ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
which gem gives me /Users/georgeclark/.rbenv/shims/gem
output from:
echo $PATH, ls -l ~/.rbenv/shims, rbenv versions, gem env
is:
/Users/georgeclark/.rbenv/shims:/Users/georgeclark/.gem/ruby/2.3.7/bin:/usr/local/sbin:/Users/georgeclark/.nvm/versions/node/v10.16.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin, ls -l /Users/georgeclark/.rbenv/shims, rbenv versions, gem env
These seem ok.. just cant figure out why it wont run, and really don't want to use sudo 😕
It was my bad.
I wasn't setting the rbenv properly.
Once I set this up with:
rbenv global 2.4.5
Then all works fine.

How to temporarily escape anaconda/conda shell environment

Once you've installed anaconda/conda, and configured your shell init file to set the path, how can you temporarily escape from that environment to use the system tools, for example the version of python that was installed natively?
If you did a default install and, therefore, followed the best practice configuration introduced in Conda v.4.4, then it is simply a matter of deactivating the base env:
conda deactivate
merv's answer is better...
Here is a way to do this on the fly without editing one's init files:
(base) ➜ ~ which python
/home/xxx/anaconda3/bin/python
(base) ➜ ~ echo $PATH
/home/xxx/anaconda3/bin:/home/xxx/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(base) ➜ ~ export PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/conda/ {next} {print}' | sed 's/:*$//')
(base) ➜ ~ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(base) ➜ ~ which python
/usr/bin/python
(base) ➜ ~

Ruby version not update using rbenv on mac

I follow this tutorial
Install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Ruby
brew install rbenv ruby-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
rbenv install 2.4.0
rbenv global 2.4.0
ruby -v
but output ruby -v still
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
running on mac OS Sierra 10.12
One of the steps of the installation is this one:
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
Which writes a command into your .bash_profile.
You need to restart your Bash session (quit the Terminal and open a new one) to take it into effect.
I was having the same issues and mislav's comment here [https://github.com/rbenv/rbenv/issues/939][1] fixed it for me.
Add eval "$(rbenv init -)" line to your .bash_profile.
Works for me.

Why do I need to add ~/.rbenv/bin to my path?

I read in rbenv can't change global ruby version that I need to add ~/.rbenv/bin to my PATH for rbenv to work.
That's also mentioned in the rbenv documentation but that directory doesn't exist as shown below:
$ ls -a ~/.rbenv/
. .. plugins shims version versions
So why do I need to add a directory that doesn't exist to my path for rbenv to work?
Edit:
#theTinMan, I tried uninstall and reinstalling, but I still don't have a ~/.rbenv/bin path. Where are you seeing in the documentation that it should be there?
$ rbenv --version
rbenv 1.0.0
$ which rbenv
rbenv () {
local command
command="$1"
if [ "$#" -gt 0 ]
then
shift
fi
case "$command" in
(rehash | shell) eval "$(rbenv "sh-$command" "$#")" ;;
(*) command rbenv "$command" "$#" ;;
esac
}
$ cd
$ ls .rbenv
plugins shims version versions
$ brew list | grep rbenv
rbenv
$
$ brew uninstall rbenv
Uninstalling /usr/local/Cellar/rbenv/1.0.0... (36 files, 61.9K)
rbenv 0.4.0 is still installed.
Remove all versions with `brew uninstall --force rbenv`.
$ brew uninstall --force rbenv
Uninstalling rbenv... (32 files, 49.9K)
$ brew install rbenv
==> Summary
🍺 /usr/local/Cellar/rbenv/1.0.0: 36 files, 62K
$ ls .rbenv
plugins shims version versions
$ rbenv -v
rbenv 1.0.0
$ rbenv versions
system
2.0.0-p648
* 2.3.1 (set by /Users/max/.rbenv/version)
$
I had the following in my .zshrc
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
But I only needed the bottom line
# export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Resources