Skip to content

Fethi's Blog

About

Setting up Headless Raspberry Pi 4 as a Home Server Part 2

1 min read

In the previous post, I talked about how to do the initial setup for Raspberry Pi. In this post, I will talk about the installation of the tools that are used most of the time in software development.

Docker

To put it briefly, Docker is a container technology that you can run an application in an isolated environment.

Installation

1-) Install Docker with snap

1sudo snap install docker

If it is ok when you execute the following command

1sudo docker run hello-world

You will see the following output

1Unable to find image 'hello-world:latest' locally
2latest: Pulling from library/hello-world
3256ab8fe8778: Pull complete
4Digest: sha256:4cf9c47f86df71d48364001ede3a4fcd85ae80ce02ebad74156906caff5378bc
5Status: Downloaded newer image for hello-world:latest
6
7Hello from Docker!
8This message shows that your installation appears to be working correctly.
9
10To generate this message, Docker took the following steps:
11 1. The Docker client contacted the Docker daemon.
12 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
13 (arm64v8)
14 3. The Docker daemon created a new container from that image which runs the
15 executable that produces the output you are currently reading.
16 4. The Docker daemon streamed that output to the Docker client, which sent it
17 to your terminal.
18
19To try something more ambitious, you can run an Ubuntu container with:
20 $ docker run -it ubuntu bash
21
22Share images, automate workflows, and more with a free Docker ID:
23 https://hub.docker.com/
24
25For more examples and ideas, visit:
26 https://docs.docker.com/get-started/

2-) Create a group named docker to be able to use docker commands without sudo

1sudo groupadd docker

3-) Add your user to the docker group

1sudo usermod -aG docker $USER

4-) Reboot your system

1sudo reboot

5-) If everything is ok you can able execute the following command without sudo

1docker run hello-world

MongoDB

Installation

1-) Pull and run the latest MongoDB from Docker with the name mongo

1docker run -d -p 27017:27017 -v ~/mongo/data:/data/db --name mongo mongo

With the -v parameter MongoDB data become persistent to Raspberry Pi's ~/mongo/data directory. In this way, we don't lose any data when we delete containers.

You can visually explore the database with MongoDB Compass also, you can use the following URL format to connect to DB via Compass

1mongodb://YOUR_RPIs_LOCAL_IP:27017

2-) You can access the mongo shell directly via the following command

1docker exec -it mongo mongo

NodeJS

Installation

1-) Install NVM (Node Version Manager)

1curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash

It will generate the following output

1% Total % Received % Xferd Average Speed Time Time Time Current
2 Dload Upload Total Spent Left Speed
3100 13527 100 13527 0 0 2423 0 0:00:05 0:00:05 --:--:-- 2968
4=> Downloading nvm from git to '/home/ubuntu/.nvm'
5=> Cloning into '/home/ubuntu/.nvm'...
6remote: Enumerating objects: 316, done.
7remote: Counting objects: 100% (316/316), done.
8remote: Compressing objects: 100% (268/268), done.
9remote: Total 316 (delta 36), reused 134 (delta 23), pack-reused 0
10Receiving objects: 100% (316/316), 169.68 KiB | 1016.00 KiB/s, done.
11Resolving deltas: 100% (36/36), done.
12=> Compressing and cleaning up git repository
13
14=> Appending nvm source string to /home/ubuntu/.bashrc
15=> Appending bash_completion source string to /home/ubuntu/.bashrc
16=> Close and reopen your terminal to start using nvm or run the following to use it now:
17
18export NVM_DIR="$HOME/.nvm"
19[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
20[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

Execute the following commands as mentioned output or exit and reopen terminal to start using NVM

1export NVM_DIR="$HOME/.nvm"
2[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
3[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

If everything is ok when you execute the following command

1command -v nvm

You will see the following output

1nvm

2-) Install latest NodeJS LTS version

1nvm install --lts

You will see an output like this

1Installing latest LTS version.
2Downloading and installing node v12.18.4...
3Downloading https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-arm64.tar.xz...
4###################################################################################################################################################################### 100.0%
5Computing checksum with sha256sum
6Checksums matched!
7Now using node v12.18.4 (npm v6.14.6)
8Creating default alias: default -> lts/* (-> v12.18.4)

Resources

© 2020 by Fethi E. UZUN. All rights reserved.
Based on Gatsby Minimal Blog Theme