Skip to content

Instantly share code, notes, and snippets.

@gagregrog
Last active January 27, 2021 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagregrog/d8ebd3e56a516d12c3dea9b2df40524b to your computer and use it in GitHub Desktop.
Save gagregrog/d8ebd3e56a516d12c3dea9b2df40524b to your computer and use it in GitHub Desktop.
Fresh install process on a Raspberry Pi, targeted at developers

Fresh Raspberries for Devs

Fresh Install Process on the Raspberry Pi, specifically for Developers.

  1. Download the Raspberri Pi OS tool for flashing your SD card from The Raspberry Pi Foundation.

  2. Plug in your SD card and use tghe tool to flash the 32-bit os to the card.

  3. When the flasher finishes, remove the card and then place it back in.

  4. Enable SSH

    $ cd /Volumes/boot
    $ nano ssh
    
    • Enter any text in the editor, then hit ctrl + x, then y, then ENTER
  5. Enable WiFi

    $ cd /Volumes/boot
    $ nano wpa_supplicant.conf
    

    And then enter your wifi info as below:

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=us
    
    network={
      ssid="yourSSID"
      psk="Your_wireless_network_password"
    }
    
    • hit ctrl + x, then y, then ENTER to exit
  6. Eject your SD card, and put it into the pi, then power up the pi.

    • Note: If you already have a raspberry pi running on your local network, and you haven't changed its hostname, you should power it off before connecting your new pi
  7. Give it a second to connect to wiFi, then from your computer, connect to the pi:

    ssh pi@raspberrypi.local
    
    • Press Y to add the device to the list of known hosts
    • When prompted, enter the default password raspberry
    • Optionally, you can use ssh-copy-id to authenticate via an ssh key.
    • Note: If you have already connected to another pi@raspberrypi.local from this computer, you may get a Host key verification failed. If this happens, simply edit your known_hosts file and remove the line that begins with raspberrypi.local
      • Use nano ~/.ssh/known_hosts and then ctrl + x, y, ENTER as before
      • After editing the file, try again to connect via ssh
  8. From the ssh connection, set up the pi by running sudo raspi-config 0. Update - Probably already up to date, but might as well

    1. System Options
      • S3 Password: Change the password to something other than the default raspberry
      • S4 Hostname: Give your device a unique hostname, so you can connect to it at <yourHostname>.local on your network
    2. Display Options
      • D1 Resolution: Choose DMT Mode 82 1920x1080 for normal HDMI displays
    3. Interface Options
      • P1 Camera: Enable the camera if you need it
      • P2 SSH: We've already enabled this
      • P3 VNC: Enable VNC if you plan on using it
    4. Localisation Options
      • L1 Locale: en_GB.UTF-8 is default, but set to what you want/need
      • L2 Timezone: Set it as needed
    5. Advanced Options
      • A1 Expand Filesystem: Just do it
  9. At this point, go ahead and reboot for the fun of it.

    • sudo reboot
    • This will terminate your ssh connection
    • After a few moments, connect again, but remember you will need to connect to the new hostname ssh pi@<yourNewHostname.local>
    • If you prefer, you can connect to your device via VNC if you set that up. Use the free VNC Viewer to do so by connecting to <yourNewHostname>.local and entering pi as the username, and the pasword you set
  10. Let's do some upgrades!

    $ sudo apt-get update
    $ sudo apt-get upgrade -y
    $ sudo apt install cmake wget p7zip -y
    
  11. Install NVM and Node

    • Follow the Git Install instructions for setting up NVM
    $ git clone https://github.com/nvm-sh/nvm.git ~/.nvm
    $ cd ~/.nvm
    $ git checkout v0.37.2
    $ . ./nvm.sh
    
    • Edit your bashrc with nano ~/.bashrc and enter the following AT THE TOP (required for non-interactive shells)
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    
    • Install the latest node with nvm install node
    • Upgrade npm with npm i -g npm
  12. Install pyenv and pyenv-virtualenv

    $ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    
    
    • Edit your .bashrc nano ~/.bashrc and add the following AT THE TOP (required for non-interactive shells)
    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"
    
    • Install build dependencies:
    $ sudo apt install libssl-dev libbz2-dev libreadline-dev libsqlite3-dev
    $ sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y
    
    • Activate pyenv: exec "$SHELL"
    • List all available versions with: pyenv install -l | grep 3.
    • Install the version you want with, for example pyenv install 3.9.1
      • See documentation for optional build flags
    • Install pyenv-virtualenv
    $ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
    
    • Update your bashrc with nano ~/.bashrc and add the following after your `"$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
    
    • Restart your shell with exec "$SHELL"
    • Create a helper function for creating virtualenvs. Add the following to the bottom of your bashrc with nano ~/.bashrc
    mkv() {
      DIR="${PWD##*/}"
      if [ $# -eq 1 ]
        then
          DIR="$1"
      fi
    
      pyenv virtualenv 3.9.1 $DIR
      echo $DIR > .python-version
    }
    
    • Now, when you enter a new project, type mkv and it will use the folder name to create a new virtualenv with the python version you specified, or use mkv someName to create the env with the name someName.
    • From now on, when you enter this directory, the python environment will automatically source
    • If you need to remove the venv in the future, type pyenv virtualenv-delete someName
    • After creating a new environment, it is a good idea to upgrade pip: pip install --upgrade pip
  13. Update your Git config (enter your name and email): nano ~/.gitconfig.

    [user]
        name = Robert Reed
        email = robert.mc.reed@gmail.com
    [alias]
        br = branch
        st = status
        cm = commit
        ch = checkout
        fe = fetch
        pu = pull origin
        hardReset = reset --hard origin/master
        pom = push origin master
        po = push origin
        clear = git rm -r --cached .
    
  14. If you are going to be developing a project with git, you will want to set up a deploy key to ease the process. For any projects you develop, take a look at this gist and follow the steps for "Set Up Deploy Key On Remote Server".

  15. If you like, edit your bashrc with some other conveniences (at the bottom):

    alias ls='ls -lFa'
    alias ma='git checkout main'
    
  16. That's it! You should be pretty well sorted now to develop on your pi. Have fun!

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