{
  "$type": "site.standard.document",
  "canonicalUrl": "https://rednafi.com/python/install-python-with-asdf/",
  "description": "Manage multiple Python versions on macOS using asdf, a unified version manager replacing pyenv, nvm, and language-specific tools.",
  "path": "/python/install-python-with-asdf/",
  "publishedAt": "2022-11-13T00:00:00.000Z",
  "site": "at://did:plc:fgtm2c26vfcj74rfmeggbyqj/site.standard.publication/3mnl6f7ob462z",
  "tags": [
    "Python",
    "TIL"
  ],
  "textContent": "I've just migrated from Ubuntu to macOS for work and am still in the process of setting up\nthe machine. I've been a lifelong Linux user and this is the first time I've picked up an OS\nthat's not just another flavor of Debian. Primarily, I work with Python, NodeJS, and a tiny\nbit of Go. Previously, any time I had to install these language runtimes, I'd execute a\nbespoke script that'd install:\n\n- Python via [deadsnake] ppa.\n- NodeJS via [nvm].\n- Go from the [official Go binary source].\n\nAlong with the hassle of having to manage three version managers, setting up multiple\nversions of Python almost always felt like a chore. I've used [pyenv] before which kind of\nfeels like nvm and works quite well in practice. However, on Twitter, I came across [this\nreply by Adam Johnson] which mentions that [asdf] can manage multiple runtimes of different\nlanguages - one version manager to rule them all. Also, it's written in pure bash so there's\nno external dependency required for the tool to work. Since I'm starting from scratch on a\nnew OS, I wanted to give this a tool to try. Spoiler alert, it works with zero drama. Here,\nI'll quickly explain how to get up and running with multiple versions of Python and make\nthem work seamlessly.\n\nPrerequisites\n\nFor this to work, I'm assuming that you've got [homebrew] installed on your system. Install\nasdf with the following command:\n\nOnce asdf is installed, you'll need to install the [asdf Python plugin]. Run this:\n\nAlso, you'll need to make sure that your system has the [asdf plugin dependencies] in place.\n\nBootstrapping Python\n\nOnce the prerequisites are fulfilled, you're ready to install the Python versions from the\nsource. Let's say you want to install Python 3.11. To do so, run:\n\nThis will install Python in the /Users/$USER/.asdf/shims/python3.11 location. Just concat\nthe command to install multiple versions of Python:\n\nSelecting a specific Python version\n\nOnce you've installed your desired Python versions with asdf, if you try to invoke global\nPython with python or python3 command, you'll encounter the following error:\n\nTo address this, you can run the next command to select the latest available version of\nPython (here it's 3.11.0) as the global default runtime:\n\nRunning this will add a $HOME/.tool-versions file with the following content:\n\nYou can also select other Python versions as the global runtime like this:\n\nIn a project, if you want to use a specific Python version other than the global one, you\ncan run:\n\nThis will add a $PATH/.tool-versions similar to the global file. Now you can just go ahead\nand start using that specific version of Python. Running this command will create a virtual\nenvironment using the locally specified Python runtime and start the interpreter inside\nthat:\n\nRemoving a runtime\n\nRunning asdf uninstall python <python-version> will do the trick.\n\n\n\n\n[deadsnake]:\n    https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa\n\n[nvm]:\n    https://github.com/nvm-sh/nvm\n\n[official Go binary source]:\n    https://go.dev/dl/\n\n[pyenv]:\n    https://github.com/pyenv/pyenv\n\n[this reply by Adam Johnson]:\n    https://twitter.com/AdamChainz/status/1591131543262867456?s=20&t=cl7NMLREat945aSICfk-9g\n\n[asdf]:\n    https://asdf-vm.com/\n\n[homebrew]:\n    https://brew.sh/\n\n[asdf Python plugin]:\n    https://github.com/asdf-community/asdf-python\n\n[asdf plugin dependencies]:\n    https://asdf-vm.com/guide/getting-started.html#plugin-dependencies",
  "title": "Installing Python on macOS with asdf"
}