DEV Community

Hastycode Andreh
Hastycode Andreh

Posted on

Using Homebrew to Install Pyenv on Ubuntu

Did you know Homebrew isn’t just for macOS? You can use it on Linux too! Often called Linuxbrew, it allows Ubuntu users to leverage Homebrew’s powerful package management features. Here’s how to install pyenv using Homebrew on Ubuntu:


1. Install Homebrew on Ubuntu

Start by installing Homebrew with this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"  
Enter fullscreen mode Exit fullscreen mode

Follow the prompts during installation. When asked, add Homebrew to your system's PATH by appending this line to your shell configuration file (~/.bashrc or ~/.zshrc):

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"  
Enter fullscreen mode Exit fullscreen mode

Reload your shell to apply the changes:

source ~/.bashrc  
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

brew --version  
Enter fullscreen mode Exit fullscreen mode

2. Install pyenv Using Homebrew

With Homebrew set up, installing pyenv is a breeze:

brew install pyenv  
Enter fullscreen mode Exit fullscreen mode

3. Configure pyenv

Finally, set up pyenv by adding this to your shell configuration file:

export PYENV_ROOT="$HOME/.pyenv"  
export PATH="$PYENV_ROOT/bin:$PATH"  
eval "$(pyenv init --path)"  
Enter fullscreen mode Exit fullscreen mode

Reload your shell once more:

source ~/.bashrc  
Enter fullscreen mode Exit fullscreen mode

4. Verify pyenv Installation

To confirm everything is working, check the pyenv version:

pyenv --version  
Enter fullscreen mode Exit fullscreen mode

Why Use Homebrew on Ubuntu?

  • Unified Management: Manage all your packages consistently across systems.
  • Ease of Use: Homebrew simplifies installations and updates.

With this setup, you're ready to install Python versions using pyenv and start managing your development environment with ease.

Give it a try and enjoy the flexibility of Linuxbrew on Ubuntu!

Top comments (0)