{"id":4864,"date":"2026-08-29T20:20:33","date_gmt":"2026-08-29T11:20:33","guid":{"rendered":"https:\/\/donguri3.net\/server-tech\/pyenv-setup-ubuntu2204-2\/"},"modified":"2026-08-29T20:20:35","modified_gmt":"2026-08-29T11:20:35","slug":"pyenv-setup-ubuntu2204","status":"publish","type":"post","link":"https:\/\/donguri3.net\/en\/server-tech\/linux-server-network\/pyenv-setup-ubuntu2204\/","title":{"rendered":"Installing and Using pyenv on Ubuntu 22.04"},"content":{"rendered":"<p><code>pyenv<\/code> is a convenient tool when you want to easily switch between and manage different versions of Python. This article explains how to install <code>pyenv<\/code> and its basic usage in an Ubuntu 22.04 environment.<\/p>\n<h3>Prerequisites<\/h3>\n<ul>\n<li>An environment with Ubuntu 22.04 installed<\/li>\n<li>Basic knowledge of Linux command-line operations<\/li>\n<\/ul>\n<div>\n<hr \/>\n<\/div>\n<h2>Installing Required Libraries<\/h2>\n<p>To use <code>pyenv<\/code>, you need to install the libraries required for building Python in advance.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>sudo apt update\nsudo apt install -y \\\\\n    make build-essential libssl-dev zlib1g-dev \\\\\n    libbz2-dev libreadline-dev libsqlite3-dev \\\\\n    wget curl llvm libncurses5-dev libncursesw5-dev \\\\\n    xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git<\/code><\/pre>\n<\/div>\n<div>\n<hr \/>\n<\/div>\n<h2>Installing pyenv<\/h2>\n<h3>Installing from the GitHub Repository<\/h3>\n<p>Install <code>pyenv<\/code> from its GitHub repository.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code><span style=\"background-color: inherit; color: inherit; font-family: inherit; font-size: var(--hcb--fz,14px);\">git clone https:\/\/github.com\/pyenv\/pyenv.git ~\/.pyenv<\/span><\/code><\/pre>\n<\/div>\n<h3>Configuring Environment Variables<\/h3>\n<p>To make <code>pyenv<\/code> available in your shell, configure your environment variables. Add the following to your <code>~\/.bashrc<\/code> or <code>~\/.zshrc<\/code>.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code># pyenv settings\nexport PYENV_ROOT=\"$HOME\/.pyenv\"\nexport PATH=\"$PYENV_ROOT\/bin:$PATH\"\neval \"$(pyenv init --path)\"\neval \"$(pyenv init -)\"<\/code><\/pre>\n<\/div>\n<p>Run the following command to apply the changes.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>source ~\/.bashrc  # or source ~\/.zshrc<\/code><\/pre>\n<\/div>\n<h3>Verifying the Installation<\/h3>\n<p>Verify that <code>pyenv<\/code> has been installed correctly using the following command.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code><span style=\"background-color: inherit; color: inherit; font-family: inherit; font-size: var(--hcb--fz,14px);\">pyenv --version<\/span><\/code><\/pre>\n<\/div>\n<div>\n<hr \/>\n<\/div>\n<h2>Installing and Managing Python<\/h2>\n<h3>Checking Available Python Versions<\/h3>\n<p>You can check the available Python versions for installation with the following command.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code><span style=\"background-color: inherit; color: inherit; font-family: inherit; font-size: var(--hcb--fz,14px);\">pyenv install --list<\/span><\/code><\/pre>\n<\/div>\n<h3>Installing a Python Version<\/h3>\n<p>To install a specific version, use the following command.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>pyenv install 3.13.1<\/code><\/pre>\n<\/div>\n<p>To check the installed versions, run the following command.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>pyenv versions<\/code><\/pre>\n<\/div>\n<h3>Switching Python Versions<\/h3>\n<h4>Global (System-wide) Setting<\/h4>\n<p>To set the Python version used system-wide, run the following.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>pyenv global 3.13.1<\/code><\/pre>\n<\/div>\n<h4>Local (Project-specific) Setting<\/h4>\n<p>To set a version used only within a specific directory, run the following.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>pyenv local 3.13.1<\/code><\/pre>\n<\/div>\n<h4>Temporary Switching<\/h4>\n<p>To temporarily switch the version, run the following.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>pyenv shell 3.13.1<\/code><\/pre>\n<\/div>\n<div>\n<hr \/>\n<\/div>\n<h2>Troubleshooting<\/h2>\n<h3>If Python Fails to Build Correctly<\/h3>\n<p>Required dependencies may be missing. Recheck your dependencies using the following command.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>sudo apt install -y make build-essential libssl-dev zlib1g-dev \\\\\n    libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \\\\\n    libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \\\\\n    liblzma-dev python3-openssl git<\/code><\/pre>\n<\/div>\n<h3>If the PATH Setting is Incorrect<\/h3>\n<p>Recheck your environment variable settings and run <code>source ~\/.bashrc<\/code>.<\/p>\n<div>\n<hr \/>\n<\/div>\n<h2>Conclusion<\/h2>\n<p>Using <code>pyenv<\/code> allows you to easily install and manage different versions of Python. This article introduced basic setup steps and commands, but please also refer to the official documentation for detailed usage and customization.<\/p>\n<p>Official Website: <a href=\"https:\/\/github.com\/pyenv\/pyenv\">pyenv GitHub<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>pyenv is a convenient tool when you want to easily switch between and manage different versions of Python. Thi [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1080,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/donguri3.net\/?p=241","footnotes":""},"categories":[1170],"tags":[51,52,105,47,100,103,106,104],"class_list":["post-4864","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-server-network","tag-git","tag-https","tag-linux","tag-python","tag-ubuntu-22-04","tag-103","tag-106","tag-104","en-US"],"_links":{"self":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/comments?post=4864"}],"version-history":[{"count":1,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4864\/revisions"}],"predecessor-version":[{"id":4867,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4864\/revisions\/4867"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media\/1080"}],"wp:attachment":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media?parent=4864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/categories?post=4864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/tags?post=4864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}