Categories: UbuntuUbuntu Feed

How to Install and Configure PyENV on Ubuntu in Minutes

If you are new to programming in Python, you might find it tricky to manage different versions of Python on your computer. This is where PyENV comes in handy. PyENV is a powerful tool that helps you switch between different versions of Python easily. Whether you’re working on an old project that needs Python 2.7 or a new one that requires Python 3.12, PyENV can make your life much easier.

In this guide, we will walk you through the process of installing and setting up PyENV on an Ubuntu system. Don’t worry if you’re not very experienced with Linux or Python. We will keep everything simple and straightforward, so you can follow along without any problems. By the end of this guide, you’ll be able to install any version of Python you need and switch between them effortlessly.

Sponsored
class="heading1">Step 1: Update Your System

First, you need to make sure your Ubuntu system is up to date. Open your terminal and type the following commands:

sudo apt update
sudo apt upgrade

These commands will update the list of available packages and their versions, and install newer versions of the packages you have.

Step 2: Install Prerequisites

PyENV needs some dependencies to work correctly. Install them by running:

sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses-dev xz-utils tk-dev libffi-dev liblzma-dev  git

This command installs all the necessary packages that PyENV requires.

Step 3: Install PyENV

Next, you need to install PyENV. The easiest way to do this is by using the Git version control system. Run the following commands in your terminal:

curl https://pyenv.run | bash

This script will install PyENV and set it up for you.

Installing pyenv on ubuntu

Step 4: Update Your Shell Configuration

After installing PyENV, you need to add it to your shell configuration so that it loads every time you open a terminal. You can do this by adding the following lines to your ~/.bashrc file:

Sponsored

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

To apply these changes, run:

source ~/.bashrc

Step 5: Install Python Versions

Now that PyENV is set up, you can install any version of Python you need. For example, to install Python 3.12, run:

pyenv install 3.12

Or you may need to install an older version like Python 2.7, type:

pyenv install 2.7

You can list all available Python versions that you can install on your system with:

pyenv install --list

Step 6: Set a Global Python Version

You can set a global Python version that will be used by default. To set Python 3.12 as the global version, run:

pyenv global 3.12

You can check the current global Python version with:

pyenv version
Pyenv set default python version

Conclusion

Congratulations! You have successfully installed and set up PyENV on your Ubuntu system. Now, you can easily manage multiple Python versions and switch between them as needed. This will make your Python development much more flexible and efficient. If you encounter any issues, remember to check the PyENV documentation and community for help.

The post How to Install and Configure PyENV on Ubuntu in Minutes appeared first on TecAdmin.

Ubuntu Server Admin

Recent Posts

Accelerating AI with open source machine learning infrastructure

The landscape of artificial intelligence is rapidly evolving, demanding robust and scalable infrastructure. To meet…

1 hour ago

Hardening automation for CIS benchmarks now available for Ubuntu 24.04 LTS

We’re pleased to release Ubuntu Security Guide profiles for CIS benchmarks. These profiles will allow…

1 hour ago

Detecting and Fixing Memory Leaks with Valgrind

Memory leaks are among the most frustrating bugs to track down in C and C++…

18 hours ago

How to Kill Processes Using Specific Ports on Linux, Windows and MacOS

Have you ever encountered issues starting a server or application because the required port is…

18 hours ago

How to Fix the “Native Host Connector Not Detected” Error for GNOME Extensions in Ubuntu 22.04

When upgrading to Ubuntu 22.04 LTS (Jammy Jellyfish), many users encounter the error message: “Although…

18 hours ago

Building optimized LLM chatbots with Canonical and NVIDIA

The landscape of generative AI is rapidly evolving, and building robust, scalable large language model…

1 day ago