Skip to content

Instantly share code, notes, and snippets.

@willbuilds
Last active February 3, 2022 05:20
Show Gist options
  • Save willbuilds/025880ff16f41cfdebe9270ecbf8a484 to your computer and use it in GitHub Desktop.
Save willbuilds/025880ff16f41cfdebe9270ecbf8a484 to your computer and use it in GitHub Desktop.
Steps for setting up a new WSL ubuntu install (zsh|asdf|node|ruby|postgres|redis|docker

Before: always trust yourself

entering a password all the time sucks. This is maybe naughty but I like it :shrug

# open sudoers file in editor (nano)
sudo nano /etc/sudoers

in the edit append the following line

<your_user_name> ALL=(ALL) NOPASSWD:ALL

save and exit. Running the following commands should no longer prompt you for a password now.

Install Dependencies

# Install curl
sudo apt install curl

# Configure source list
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

# Install dependencies
sudo apt -y update
sudo apt -y install autoconf bison git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev libgdbm-dev libncurses-dev

Optional: Install Zsh

sudo apt install zsh

Optional: Install Ohmyzsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

see https://github.com/ohmyzsh/ohmyzsh for more

Install Asdf

download asdf

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.9.0

add asdf to the ohmyzsh plugins definition in zshrc (sudo nano ~/.zshrc)

plugins=(asdf)

and append the following to bottom of zshrc

# append completions to fpath
fpath=(${ASDF_DIR}/completions $fpath)
# initialise completions with ZSH's compinit
autoload -Uz compinit && compinit

see https://asdf-vm.com/guide/getting-started.html for more

Install Ruby, Node, and Yarn with asdf

# Add asdf plugins
asdf plugin add ruby
asdf plugin add nodejs
asdf plugin add yarn

# install a version of ruby (replace latest with desired versions)
asdf install ruby latest
asdf install nodejs latest
asdf install yarn latest

# add to global
asdf global ruby latest
asdf global nodejs latest
asdf global yarn latest

# confirm installation
ruby -v
node -v
yarn -v

see https://asdf-vm.com/guide/getting-started.html#_4-install-a-plugin for more

Install Docker

Docker Desktop should be installed on Windows, with WSL2 Backend enabled. See https://docs.docker.com/desktop/windows/install/

Docker will be piped to your default wsl distribution, but you can select additional distributions also, see screenshot. image

Once this is done (you may need to restart terminal and/or windows itself), enter docker ps in wsl to see a (currently blank) list of docker images.

To fix an issue where docker desktop needs further config to support Elasticsearch containers, add this to your .zshrc file (or .bashrc)

wsl.exe -d docker-desktop sh -c "sysctl -w vm.max_map_count=262144"

Install Postgres

# install postgres
sudo apt install postgresql

# set password for postgres user
sudo passwd postgres

# start the postgres service (you'll need to do this on each restart, or configure systemd or an init.d script)
sudo service postgresql start

Configure SSH for Github

I like to use the same SSH key for my different WSL distributions (they aren't different machines).

So, If you already have an ssh key configured on an existing distribution:

copy the existing ssh key files into your new distribution. There's probably an easier way to copy between distros, but I literally create the files with

touch ~/.ssh/id_xyz
touch ~/.ssh/id_xyz.pub

and then copy-paste the respective contents from your existing distro with good old clipboard.

If you don't already have an ssh key configured:

ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"
# press enter to select default path
# press enter again to confirm a blank passphrase

If you don't know if you have ssh configured

ls -l ~/.ssh/id_*.pub

configure and test w github

If you generated a new key, add the public key to github (https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)

Test out your ssh auth:

ssh -T git@github.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment