Skip to content

Instantly share code, notes, and snippets.

@candeira
Forked from ned2/ubuntu-ec2-init.sh
Created June 27, 2021 01:08
Show Gist options
  • Save candeira/6f5bdd772f2dc3bb994f4ac7ae5f73bc to your computer and use it in GitHub Desktop.
Save candeira/6f5bdd772f2dc3bb994f4ac7ae5f73bc to your computer and use it in GitHub Desktop.
A Bash script for initialising a clean Ubuntu installation and user account with a pyenv-based workflow.
#!/usr/bin/env bash
# Author: Ned Letcher
#
# This bash script is designed to configure a clean Ubuntu installation (eg new
# EC2 instance) with a somewhat opionated set of packages and tools for working
# on Python projects. In addition to installing a range of packages for dev
# work, it installs pyenv for the current user, overwriting the current .profile
# and modifying the existing .bashrc to make sure pyenv is configured correctly.
# make sure system is updated
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -yq \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confnew" \
dist-upgrade
# install pyenv/python deps
sudo DEBIAN_FRONTEND=noninteractive apt-get install \
-y -q --no-install-recommends \
make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libreadline-dev \
libsqlite3-dev wget curl llvm xz-utils tk-dev libxml2-dev \
libxmlsec1-dev libffi-dev liblzma-dev
# install dev tools
sudo DEBIAN_FRONTEND=noninteractive apt-get install \
-y -q --no-install-recommends \
git docker.io npm htop byobu emacs vim direnv awscli jq tig
# install data deps
sudo DEBIAN_FRONTEND=noninteractive apt-get install \
-y -q --no-install-recommends \
libsnappy-dev libsqlite3-dev
# get scripts for user's $HOME/bin
mkdir -p $HOME/bin
curl -L https://github.com/git/git/raw/master/contrib/completion/git-prompt.sh > $HOME/bin/git-prompt.sh
# install pyenv
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
# create a new .profile that initialises pyenv *before* sourcing .bashrc
cat > $HOME/.profile <<'_EOF'
if [ -d ${HOME}/.pyenv/bin ]; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
fi
if [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
_EOF
# Append needed pyenv initialisation to current .bashrc
cat >> $HOME/.bashrc <<'_EOF'
if [ -x "$(command -v pyenv)" ]; then
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
_EOF
@candeira
Copy link
Author

So the reason you don't install GPU drivers and stuff is because AWS already provides them in the GPU instances?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment