Skip to content

Instantly share code, notes, and snippets.

@tforster
Last active December 27, 2021 20:28
Show Gist options
  • Save tforster/6164e0ac24e13b297d192d0d071dbde4 to your computer and use it in GitHub Desktop.
Save tforster/6164e0ac24e13b297d192d0d071dbde4 to your computer and use it in GitHub Desktop.
[New Linux Setup] A collection of shell snippets useful when setting up a new Linux instance #linux #setup

New Linux Setup

Setting up Linux systems is a frequent activity for me. Whether it is configuring a Docker image, setting up a new SDCard for a Raspberry Pi or migrating from one laptop to another. This README is an ongoing record of installation snippets that I copy and paste.

Create Some Useful Directories

md ~/dev
md ~/temp

Ensure Everything is Current

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y

Install some basic dependencies

sudo apt-get install -y curl \
    unzip \
    git \
    zsh \
    python2.7 \
    apt-transport-https \
    ca-certificates \
    software-properties-common

Set Git Defaults

git config --global user.email "troy.forster@gmail.com"
git config --global user.name "Troy Forster"

Install Hyper

Download the latest Hyper from their website. Manually install by double-clicking.

xdg-open https://releases.hyper.is/download/deb

Install some useful hyper plugins.

hyper i hyper-pane
hyper i hyper-tabs-enhanced
hyper i hyper-night-owl

Open hyper so we can work in it for the remainder: hyper. Don't forget to pin to favourites if using Ubuntu Desktop.

Install ZSH

ZSH is a great alternative to bash and supports a multitude of useful plugins for developers

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
chsh -s `which zsh`
zsh

Configure my preferred theme by copying and pasting the following...

local ret_status="%(?:%{$fg_bold[green]%} :%{$fg_bold[red]%} )"
PROMPT='%{$fg[cyan]%}%d%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"

...into nano ~/.oh-my-zsh/themes/tforster.zsh-theme.

Create ~/.zshrc

export ZSH="/home/tforster/.oh-my-zsh"
ZSH_THEME="tforster"

plugins=(
  git docker vscode aws
)

source $ZSH/oh-my-zsh.sh

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

# Add Python packages/scripts to path
alias python=python3
alias pip=pip3
export PATH=$PATH:$(python3 -m site --user-base)/bin

# tabtab source for packages
# uninstall by removing these lines
[[ -f ~/.config/tabtab/__tabtab.zsh ]] && . ~/.config/tabtab/__tabtab.zsh || true

unalias l
function l() { ls -la --color "$@" | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(" %0o ",k);print}'; }

NVM and latest Node

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Download and install latest node nvm install node

Configure NPM defaults

npm config set init.author.name "Troy Forster"
npm config set init.author.email "troy.forster@gmail.com"
npm config set init.author.url "http://www.tforster.com"
npm config set init.license "MIT"
npm config set init.version "1.0.0"

Install MongoDb Community Edition

Check https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ to ensure the key and multiverse lines are the latest.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start

Install AWS Cli

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo /usr/bin/python2.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Edit the credentials and config files in ~/.aws/.

Install Visual Studio Code

xdg-open https://code.visualstudio.com/ to open and download the latest .deb file. Once installed, open VSCode and install the code-settings-sync extension. Press alt+shift+d and follow the prompts to sync down the latest extensions and personal settings.

Install Some Useful Snaps

snap install postman
snap install slack
snap install spotify

Fiddly Bits

Install Docker

See https://docs.docker.com/engine/installation/linux/ubuntu/ for additional details and confirm the latest apt-key.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update -y
sudo apt-get install docker-ce -y

Notes for Docker on Windows 10 Home Edition

Docker Windows for 10 Home uses Docker Toolbox. To use Docker in Windows and Windows Sub System for Linux (WSL) the Docker daemon must run under Windows. The docker and docker-compose clients will work under WSL as TCP is available between hosts.

  1. Run the .msi on https://docs.docker.com/toolbox/toolbox_install_windows/

  2. Install Docker for Ubuntu as per instructions above, inside Linux Subsystem for Windows aka Bash

  3. Install docker-compose for Ubuntu using sudo apt-get install docker-compose

  4. Run Docker toolbox interactive shell

  5. docker-machine env

  6. Edit the output to convert cert path from Windows format to Linux format to get something like...

    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.99.100:2376"
    export DOCKER_CERT_PATH="/mnt/c/Users/tforster/.docker/machine/machines/default/"
    export DOCKER_MACHINE_NAME="default"
    export COMPOSE_CONVERT_WINDOWS_PATHS="true"

    ... then copy and paste into Windows Bash and test with docker run hello-world

For convenience symlink the WSL dev folder ln -s /mnt/c/Users/tforster/dev ~

Additional Installs for ChromeOS

Cleanup and existing Crouton chroot sudo rm -rf /usr/local/chroots/<chroot-name>/. Note that this will be deprecated soon when Google releases Crostini.

Create a lightweight Crouton chroot for with XFCE desktop sudo sh ~/Downloads/crouton -r trusty -t xiwi,xfce

Install the ARM version of Visual Studio Code from https://code.headmelted.com/ with . <( wget -O - https://code.headmelted.com/installers/apt.sh )

Additional Tools

jq

sudo apt-get install jq

joy

git clone joy followed by npm i, then install jq dep

download cascadia font, unzip and move mv *.ttf /usr/share/fonts/truetype

https://github.com/microsoft/cascadia-code/releases

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