Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the path for Pyenv

I am trying to set the load path for Pyenv in my server .bashrc file.

I am following this tutorial where it asks us to set pyenv to the load path

However, in my .bashrcfile, I already see the below commands

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
 eval "$(pyenv init -)"
fi

And how is it different from the below provided in the tutorial shared above?

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

May I know what does if...fi block does in the code shown above?

like image 653
The Great Avatar asked Jun 07 '26 15:06

The Great


1 Answers

It's mostly bash's syntax.

#1.

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

is equivalent to

export PATH="$HOME/.pyenv/bin:$PATH"

as in the first case, you're declaring a variable named PYENV_ROOT then using it.

#2.

if and fi are how you write if-statements in bash.

#3.

command -v pyenv is used to execute a command (pyenv) in this case, the -v option prints the pathname e.g.

$ command -v python
/usr/bin/python
if command -v pyenv 1

means that if the command pyenv is found, then execute eval "$(pyenv init -)"

#4.

Here, >/dev/null 2>&1; is used to discard the output. read more about it this answer.

Hence, two blocks of code are almost same, the only differences are: the first one has a if-block and second one has one extra command eval "$(pyenv virtualenv-init -)".

like image 156
kHarshit Avatar answered Jun 09 '26 06:06

kHarshit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!