Set Up Ubuntu and WSL - iff133/first GitHub Wiki

Ubuntu

  • Download ubuntu from the app store
  • Once installed launch it
  • Set up UNIX password and username

Generate an SSH key:

  • Next we want to make ourselves an SSH key for our user. This will come in handy later. Run the command ssh keygen and follow the prompts. You don't have to set a passphrase for your key.
  • ssh-keygen
  • Do: cat ~/.ssh

Add public key to Gitlab

  • A list should appear and do again: cat ~/.ssh/id_rsa.pub
  • Your public key should appear and it starts with ssh-rsa copy this key If you want to find out when was the last time the public key was changed do either:
  • ls -l ~/.ssh/id_rsa.pub
  • stat ~/.ssh/id_rsa.pub

2. Once you have run cat ~/.ssh/id_rsa.pub go to settings in gitlab: image

3. Under Settings choose ssh keys: image

4. Add the key to the ssh key by pasting the perviously copied key into the ssh settings: image

Virtual Environment

  1. Update Ubuntu Packages: sudo apt-get update
  2. Install Python 3: python --version and python3 --version
  3. If you do not have python3 installed, run the following: sudo apt install python3
  • In my case, my ubuntu by default came with python3 and did not have python2 when the above commands were run. For future commands, I will be running python3 commands by just typing python. You can set this up using a bash alias. Run the following to make future python3 commands run by simply typing python: echo "alias python=python3" >> ~/.bashrc
  • Now open a new terminal for these changes to take effect. You can close your windows and open a new one. Once done, you can check the alias has worked by typing python --version which should now show the same output you got previously from running python3.
  1. Install PIP 3
  • sudo apt install python3-pip -y
  • It is also useful to make an alias for pip3 and call it simply pip. Future commands will be running pip as an alias for pip3 make a pip3 alias: echo "alias pip=pip3" >> ~/.bashrc
  • Let us also as best practice, make sure our pip is up to date: pip install --upgrade pip
  1. Install and Activate VENV
  • Next we need to install a package called venv: sudo apt-get install python3-venv -y
  • Then we need to make a virtual env. You can run this command with any name you choose, however the internal docs git repository is setup to ignore your virtual env if you call it venv or anything named venv*. So with this in mind let's run: python -m venv ~/venv
  • Activate virtual environment: source ~/venv/bin/activate
  • https://internal.demarq.io/docs/#references
  1. Install packages: pip install -r /mnt/c/alp/alppackages.txt

Install PostgreSQL 12 on Ubuntu

  • sudo apt install postgresql-client-common
  • Add PostgreSQL 12 repository: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  • After importing GPG key, add repository contents to your Ubuntu 18.04/16.04 system: echo "deb http://apt.postgresql.org/pub/repos/apt/ lsb_release -cs-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list
  • Now the repository has been added successfully, update the package list and install PostgreSQL 12 server and client packages on your Ubuntu 20.04/18.04/16.04 Linux system.
  • sudo apt update
  • sudo apt -y install postgresql-12 postgresql-client-12
  • https://computingforgeeks.com/install-postgresql-12-on-ubuntu/

Generate ~/.pgpass file

  • touch ~/.pgpass
  • chmod 600 ~/.pgpass
  • vi ~/.pgpass
  • Add the following:
alp4.demarq.uk:54320:postgres:isabel:Jg7ik4n4gG
alp4.demarq.uk:54320:alp:isabel:Jg7ik4n4gG
  • Test it by running: psql -U isabel -h alp4.demarq.uk -p 54320 -d alp

Edit ~/.bashrc profile

  • Add the following code at the end of the ~/.bashrc file in order to display the git branch in the terminal
parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\u@\h \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]$ "

Add public key to alp5 server

  • In order to know if the connection to the server wasn't affected run either: ssh alp5 or ssh [email protected]
  • If you get these warnings:
ssh: Could not resolve hostname alp5: Name or service not known

The authenticity of host '10.2.0.99 (10.2.0.99)' can't be established.
ECDSA key fingerprint is SHA256:CeB1TsZpwkZMbm9PbioJfEzjwvEODU3ZiSF/e/jedd4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.2.0.99' (ECDSA) to the list of known hosts.
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

then you must give the your newly generated public key to one of the Richards so that it can be added to the host.

Edit Config file

  • sudo -i
  • cd .ssh/
  • vi config
  • Add:
Host *
  ForwardX11 yes
Host alp5
  HostName alp5.demarq.uk
  User isabel_freitas
  IdentityFile ~/.ssh/id_rsa
  Compression yes
  ForwardAgent yes
  ForwardX11 yes

Create a ~/etc/wsl.conf file if one does not exist

  • cd ~/etc/
  • touch wsl.conf
  • Add this to the file:
[network]
generateResolvConf = false

Install docker

Install

  • sudo apt-get update
  • sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • sudo apt-key fingerprint 0EBFCD88
  • Then:
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

INSTALL DOCKER ENGINE

  • sudo apt-get update
  • sudo apt-get install docker-ce docker-ce-cli containerd.io
  • sudo docker run hello-world If an error shows up.. is the docker daemon running? This means that you must close all ubuntu windows in order for the changes to take effect.. then run sudo docker run hello-world

YOU MUST RESTART ALL UBUNTU TERMINALS IN ORDER FOR THE DOCKER CHANGES TO TAKE PLACE .. ONLY THEN WILL YOU BE ABLE TO RUN IT

  • Then: sudo groupadd docker
  • sudo usermod -aG docker $(whoami)

Install yarn