Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

pyenv is installed but the shell cannot find it

ErrorCommand 'pyenv' not found, did you mean:

Short answer

The shell finds pyenv only if its bin folder is on PATH. Either pyenv was never installed, or the three setup lines were not added to the file your shell reads at startup. Install it with the official installer, add the lines to .bashrc or .zshrc (and the login file if needed), then restart the shell.

  • Applies to pyenv 2.6, Ubuntu 24.04, bash 5, zsh 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the folder exists at all. That separates 'not installed' from 'not on PATH'.

    ls -d ~/.pyenv
    echo "$PATH" | tr ':' '\n' | grep pyenv
    echo "$SHELL"
  2. 2Match what you see, then jump to its fix

    1. 1ls: cannot access '/home/you/.pyenv': No such file or directorypyenv was never installedFix
    2. 2~/.pyenv exists, but pyenv is not in PATHThe setup lines are missing from your shell's startup fileFix
    3. 3pyenv works in a new terminal window but not over SSH or in a login shellLogin shells and SSH sessions read a different fileFix

What does the error look like?

  • Command 'pyenv' not found, did you mean:
  • pyenv: command not found

Cause 1 of 3

pyenv was never installed

1Check

The README's automatic installer is the supported route on Linux, and it puts pyenv under ~/.pyenv.

ls -d ~/.pyenv

2Fix

Run the automatic installer that the pyenv README recommends on Linux. Install Python build dependencies before the first pyenv install.

curl -fsSL https://pyenv.run | bash

3Verify

The folder exists and the binary answers.

~/.pyenv/bin/pyenv --version

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The setup lines are missing from your shell's startup file

1Check

pyenv needs PYENV_ROOT, its bin directory on PATH, and the init line. Look for them in the file your shell reads.

grep -n pyenv ~/.bashrc ~/.zshrc ~/.profile 2>/dev/null

2Fix

Add the three lines for your shell (bash shown). For zsh put them in ~/.zshrc and use pyenv init - zsh.

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc

3Verify

Restart the shell, then run pyenv.

exec "$SHELL"
pyenv --version

Confirmed by github.com

Did this fix it?

Cause 3 of 3

Login shells and SSH sessions read a different file

1Check

The README says to put the same lines in ~/.profile, ~/.bash_profile or ~/.bash_login as well, for login shells. It also warns that if BASH_ENV points at .bashrc, the eval line belongs in .bash_profile.

echo "$BASH_ENV"; ls -a ~ | grep -E 'profile|bash_login'

2Fix

Repeat the three lines in the login file your shell actually uses.

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init - bash)"' >> ~/.profile

3Verify

Open a fresh login shell.

bash -l -c 'pyenv --version'

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Install pyenv per user, not with sudo.
  • After editing a startup file, restart the shell with exec "$SHELL" instead of opening a half-configured one.
  • Install the Python build dependencies before pyenv install, as the README asks.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.