My Go-To Script for New Cloud Instance Setup

Published on 2025-04-13

As an ML engineer, I often spin up new VM instances (especially Vertex AI Workbench instances) for running experiments. But all the utilities, aliases, and keyboard shortcuts that I’m used to on my local machine are missing. Spending time setting up the environment from scratch again and again is annoying.

I always use this bash script (GitHub Gist) I created, which transforms a vanilla VM into my personalized workbench in seconds. It installs essential command-line utilities like tmux, fzf, htop, and uv, and configures my shell (.bashrc), Vim (.vimrc), and tmux (.tmux.conf) just the way I like them.

This script handles:

Whenever I create a new instance, I just run this single script and immediately feel at home. No more manually installing the same tools or tweaking config files every single time!

Hope this little idea helps streamline your workflow too!

#!/bin/bash
sudo apt-get update & sudo apt-get install -y git vim tmux htop curl wget ncdu locales locales-all
# for debian systems
# https://serverfault.com/a/894545
sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen
sudo locale-gen
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
curl -LsSf https://astral.sh/uv/install.sh | sh
echo 'eval "$(uv generate-shell-completion bash)"' >> ~/.bashrc
uv tool install thefuck
cat << 'EOF' > ~/.bashrc
# setup useful aliases
alias l='ls -lah --color=auto'
alias vea='./.venv/bin/activate'
alias cap='conda activate pytorch'
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../..'
alias mkdir='mkdir -p'
alias df='df -h'
alias du='du -h'
alias fk='thefuck'
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# History settings
export HISTSIZE=10000
export HISTFILESIZE=10000
export HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --border --inline-info"
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
EOF
# Set up Vim configurations
cat << 'EOF' > ~/.vimrc
syntax on
set number
set autoindent
set tabstop=4
set shiftwidth=4
set expandtab
set incsearch
set hlsearch
set ignorecase
set smartcase
set mouse=a
EOF
# Configure tmux with a better prefix and mouse mode
cat << 'EOF' > ~/.tmux.conf
# Remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Enable mouse mode
set -g mouse on
# Split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
# Reload config file
bind r source-file ~/.tmux.conf
# Better pane navigation
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# Basic status bar colors
set-option -g status-style bg=black,fg=white
# Window status
set-window-option -g window-status-current-style bg=blue,fg=black
EOF
# source the profile to apply changes
source ~/.bashrc
echo "VM environment setup complete!"
view raw vm-setup.sh hosted with ❤ by GitHub