Anaconda Installation on Ubuntu: Engineering Best Practices
Python dependency hell is real on multi-user Ubuntu systems, and global pip installs are a repeat offender. Anaconda streamlines package management, reproducibility, and environment isolation—but only if installed and maintained thoughtfully.
Pre-Install Checklist
- Ensure all system packages are current.
- Avoid using sudo for anything inside Anaconda after installation—unintended access control issues and conflicts with system Python are common.
sudo apt update && sudo apt upgrade -y
sudo apt install wget -y
Fetching the Anaconda Installer (Current Release)
Hardcoding old URLs is a frequent oversight. Validate and fetch the latest version (Anaconda3-2023.07-1-Linux-x86_64.sh
at time of writing):
wget https://repo.anaconda.com/archive/Anaconda3-2023.07-1-Linux-x86_64.sh
To prevent corrupted installation binaries—a real pain to debug—verify the checksum:
wget https://repo.anaconda.com/archive/Anaconda3-2023.07-1-Linux-x86_64.sh.sha256
sha256sum -c Anaconda3-2023.07-1-Linux-x86_64.sh.sha256
A successful check outputs:
Anaconda3-2023.07-1-Linux-x86_64.sh: OK
Failure? Delete the installer and try again with a reliable network.
Non-Root Installation
Leave system paths untouched. Always install Anaconda in your user directory (~/anaconda3
unless policy dictates otherwise).
chmod +x Anaconda3-2023.07-1-Linux-x86_64.sh
./Anaconda3-2023.07-1-Linux-x86_64.sh
Installer prompts include:
- Reviewing the license (spacebar to scroll).
- Confirming installation path.
- Accepting or rejecting shell initialization (
conda init
). Choose “yes” unless you have multiple conflicting environment managers, in which case manual activation is preferable.
Reload Your Shell
Make conda
available immediately:
source ~/.bashrc # or ~/.zshrc if you use zsh
Verify operational status:
conda --version
Expected:
conda 23.7.2
Version mismatch? Check ~/.bashrc
for path errors or conflicting initializations.
Update Conda Base Environment
Neglecting this step introduces outdated dependencies and well-documented security issues.
conda update -n base -c defaults conda -y
Gotcha: Updates can be slow due to large resolver graphs, especially on minimal hardware.
Isolate Project Environments
Never install packages in base. Instead, define a dedicated environment:
conda create -n data-science python=3.11 -y
conda activate data-science
Example: Install critical data packages.
conda install numpy pandas scikit-learn matplotlib -y
Switch environments explicitly:
conda deactivate
Why not share envs globally? Library conflicts are common (e.g. cudatoolkit
, Jupyter extensions).
Prune and Maintain
Environment bloat is inevitable. List installed packages, prune obsolete dependencies:
conda list -n data-science
conda remove -n data-science unused-package -y
To completely retire an obsolete project:
conda env remove -n old_env -y
Side note: Disk usage balloons quickly—default installs can reach >4 GB.
Optional: Miniconda for Minimalists
The full Anaconda installer includes ~250 packages by default, most of which go unused in production. For lean deployments, Miniconda trims the footprint but requires manual installs:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# Repeat install and environment steps as above
Trade-off: extra time spent building each environment.
Shell Initialization: Balancing PATH Hygiene and Usability
Automatic modification of .bashrc
or .zshrc
via conda init
can add overhead to every terminal session—noticeable on remote or resource-constrained machines. If latency is a concern:
- Comment out conda-related lines in your shell config.
- Manually activate conda only when required:
source ~/anaconda3/etc/profile.d/conda.sh conda activate base
Known issue: Forgetting to activate conda leads to “conda: command not found” errors.
Cleaning Up
After installation is verified and environments are configured:
rm Anaconda3-2023.07-1-Linux-x86_64.sh*
Troubleshooting
Symptom | Possible Cause | Resolution |
---|---|---|
conda: command not found | Shell initialization incomplete | source ~/.bashrc or manual activation |
Installer: “Permission denied” | Non-executable installer file | chmod +x <installer> |
Environment activation slow | Heavy PATH or conda init in sluggish shells | Use manual activation, clean up .bashrc |
Conflicting system Python (e.g. venv/pip) | Incorrect PATH order; mixing package managers | Never pip install outside conda envs |
Tip: If Jupyter kernels don’t appear, register manually:
python -m ipykernel install --user --name data-science
ASCII: Environment Management Workflow
+-------------+ +----------+ +-------------------+
| Sys Upgrade | ---> | Anaconda | ---> | Project Envs (n) |
+-------------+ +-----+----+ +-------------------+
\-> Prune / Remove |
\-> Package Install |
Summary
Anaconda’s value lies in disciplined use—non-root install, minimal shell interference, real isolation per project. Consider Miniconda for lightweight needs. Never skip environment maintenance or updates. And always verify, don’t trust, downloaded installers.
Note: For production servers or CI pipelines, evaluate containerized Python stacks (e.g. Docker with mamba/conda). Anaconda excels for interactive and research workflows, but isn't always optimal for headless deployment.