Look, installing Conda on EC2 doesn't need to be complicated. After setting this up across hundreds of instances, here's my approach that just works.
The Fast Track
Skip the fluff. Here's what actually works:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
~/miniconda/bin/conda init bash
source ~/.bashrc
Done. That's it. If you're in a hurry, you can stop reading here.
When Things Break
The Command Not Found Thing
Got the "conda: command not found" error? Yeah, we've all been there. The -b flag skips initialization. Just run:
~/miniconda/bin/conda init bash
source ~/.bashrc
Fixed. Moving on.
Existing Installation
ERROR: File or directory already exists: '/home/ec2-user/miniconda'
Two options:
# Quick update
bash ~/miniconda.sh -u -b -p $HOME/miniconda
# Or nuke it and start fresh
rm -rf $HOME/miniconda && bash ~/miniconda.sh -b -p $HOME/miniconda
Production Setup
Here's my actual production setup script. Copy-paste and thank me later:
#!/bin/bash
sudo yum update -y
# Skip if you've handled these in your AMI
sudo yum install -y bzip2 wget git
# Base install
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
~/miniconda/bin/conda init bash
source ~/.bashrc
# The stuff you actually need
conda config --add channels conda-forge
conda config --set channel_priority strict
conda clean -a -y # Trust me on this one
# Create your env
conda create -n prod python=3.11 -y
conda activate prod
conda install numpy pandas scikit-learn -y # Add your packages
For the DevOps Folks
Throw this in your user data and forget about it:
#!/bin/bash
cat <<'EOF' > /home/ec2-user/setup_conda.sh
#!/bin/bash
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
~/miniconda/bin/conda init bash
EOF
chmod +x /home/ec2-user/setup_conda.sh
sudo -u ec2-user /home/ec2-user/setup_conda.sh
The "Why" Behind the Choices
- Miniconda over Anaconda: Smaller footprint, faster installs. You don't need the bloat.
- conda-forge first: Better packages, fewer headaches.
- Always clean after big installs: Saves space, prevents weird caching issues.
- Separate envs: Just do it. Future you will be grateful.
Storage Notes
Quick reality check before you start:
df -h
Miniconda needs about 400MB. Your envs will grow. Plan accordingly or attach an EBS volume.
Container World
If you're using containers (and you probably should be), here's your Dockerfile snippet:
FROM amazonlinux:2
RUN yum update -y && \
yum install -y bzip2 wget && \
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /miniconda.sh && \
bash /miniconda.sh -b -p /opt/conda && \
rm /miniconda.sh
ENV PATH="/opt/conda/bin:${PATH}"
RUN conda install -y python=3.11 && \
conda clean -a -y
WORKDIR /app
One Last Thing
Always export your environment:
conda env export > environment.yml
Don't be that person who can't reproduce their env six months later.
That's it. No fluff, just what works. If you've got questions, you know where to find me.
Top comments (0)