Installing Debian (64-bits) on Raspberry Pi 4
Introduction
I have a collection of raspberry pi computers with the oldest one being from 2013. As it gave up the ghost recently, I decided to buy the latest Pi 4. Since the 4GB RAM version was available from Okdo, I decided to use it as a database and development server. Raspbian is a 32-bits operating system, and I needed to work with a 64-bits o/s, and so I decided to install debian. Incidentally, if you wish to install mongodb on your raspberry pi, you will need to install a 64-bits operating system. Anyway, here is what I did.
Caveat
But first, a caveat. I shall not tell you which button to press in nano or vi, etc., when editing a file. I will assume you know how to use your favorite editor and what most linux commands do. So here goes…
What You Need
- A Raspberry Pi 4 single-board computer.
- A USB Type-C power adapter for Raspberry Pi 4.
- A 16GB or higher capacity microSD card or USB drive.
- A card reader for flashing Debian on the microSD card; not needed if using USB drive.
- A computer/laptop for flashing the microSD card.
- A keyboard and a mouse.
- A micro-HDMI to HDMI cable.
Download Debian
Go to the official site at https://raspi.debian.net/ and click on the “Download Tested Images” tab.
As Figure 1 shows, the image available is an xz-compressed image. The ‘Family’ column implies that it is for Pi 4, and the next column says that it was tested on a computer with 4GB of RAM. Download the image that you want to install on your Pi as there is a long list of images.
Flash your SD card or USB drive
Once downloaded, flash it with Raspberry Pi Imager, which is available for Mac, Windows and Ubuntu. You will need to choose the ‘Use Custom’ list item to select the image file you downloaded — this is right at the end of the list for ‘Operating System’. I have chosen the Bookworm Debian image as Figure 2 shows.
Once you have selected the image and the storage device (SD card or USB drive) that you want to flash the image to, you can click the ‘Write’ button.
Connect up your Pi 4
After the image has been flashed onto your card/drive, hook up your Pi to a monitor, insert the drive/card, and attach the keyboard mouse. Then power it up!
First Tasks
Log in as root — no password is required. Your first task will be to assign a root password using the passwd command. Your next task will be to add a user using the adduser commands:
adduser -m <username>
passwd <username>
usermod -aG sudo <username>
The above commands create the user, give him a password, and adds him to the group sudo.
Your third task will be to edit the file /etc/network/interfaces.d/wlan0 as follows.
allow-hotplug wlan0
iface wlan0 inet dhcp
# iface wlan0 inet6 dhcp
wpa-ssid <YOUR SSID>
wpa-psk <YOUR PASSWORD>
Ensure that you add the correct SSID and password for your wifi network. After saving it, restart the computer (use the command reboot or systemctl reboot) and log in as root. Ensure that you have an ip address by using the command ip a and that your networking works by pinging google.com.
Update the System
Simply use the commands apt update and then apt upgrade — accept the default Y to proceed when necessary.
You may also wish to change the host name of your Pi system. To do so, use the following instructions.
hostnamectl set-hostname udupi
where udupi is your host’s name; change it to suit.
Use the command vi /etc/hosts to edit the hosts file so that your Pi’s host name appears after localhost, as Figure 3 shows.
SSH
Having obtained the Pi’s ip address using the ip a command, switch over to your laptop or PC and ssh into the Pi using the username and password of the new user you created. Accept any prompts to proceed, as Figure 4 shows.
We are almost done. We now just need to verify that sudo works by first installing it. Make sure you type the command below on the Pi’s keyboard and not at the ssh session because we still do not have sudo capability:
apt install sudo
Now, at the ssh session, test if sudo works by typing some command like sudo apt update. If it works, you are good to go to the next step.
Locales
Perhaps you may not need this if you are in the US, but you will need to install locales and configure your Pi to use the right one. So first install the locales: sudo apt install locales and then configure your Pi, as Figure 5 shows, using the command:
sudo dpkg-reconfigure locales
Choose the C UTF locale, if prompted, once you go past the screen shown in Figure 5.
Add Tools
All the commands from now on will be as the user you created using the ssh session. Feel free to reboot your Pi in case you want to make a clean start.
We want to add manual pages first. so install them with:
sudo apt install man mangages man-db groff
Then we will add vim (this is my favorite editor), although you may want to install any other editor you prefer such as emacs.
sudo apt install vim vim-scripts vim-doc
Then git client:
sudo apt install git
Let us now install zsh and make it the default for our user account, as shown in Figure 6:
sudo apt install zsh
chsh <username>
…and finally, clone the settings for vim and zsh from your github repository. In this example, I am using mine:
Then, untar as follows:
tar -C ./ -xvzf ux-settings/vim-setup.tgz
tar -C ./ -xvzf ux-settings/zsh-setup.tgz
You may exit and login again, as well as use vim, to check whether the settings have been applied. One remaining task is for you to decide whether you want to have fortune read out whenever you log in. If so, then install it together with cowsay:
sudo apt install cowsay fortunes fortune-mod
If you do not want to have fortune or cowsay, then you will need to edit the .zshrc file to get rid of the command that invokes them.
Additional Tools and Utilities
I like to have two other utilities on my machines: wget and curl. So let us install them:
sudo apt install curl wget
Two other utilities that seem to be missing from the debian image for Pi are tree and htop. Both are pretty useful when you want to know a bit more about your system. So, let us install them:
sudo apt install htop tree
Figure 7 above shows htop in operation on my Pi 4 — it shows that the device has 4 CPU cores and has 3.7G of RAM available. Figure 8 shows the output of running the tree command on my home directory.
And finally, I like to have locate on my linux and unix machines so that I can search for any files or directories on my device. The command locate works with updatedb that needs to be run as root in order to create a database of indices to all the files on your device. So install locate and run updatedb, as follows.
sudo apt install locate
sudo updatedb
You can now run the locate program to search for and locate any file on your device.
Add Build Tools
We essentially need gcc, make and the various C/C++ utilities for building C programs if we are to do anything useful on our Pi. These, as well as python, are missing from the debian image. And so let us install them.
sudo apt install build-essential flex bison automake gdb
sudo apt install python3 python3-venv
Now create a symbolic link for python:
sudo ln -sn /usr/bin/python3 /usr/bin/python
Check it out:
python
You are all set. If you want to do some javascript coding on your Pi, then you may want to install node.js using nvm. To do so, just follow the instructions for nvm installation at its github site:-
Finis
Well, that’s it! We have a brand new debian build on a Raspberry Pi 4; happy coding and have fun!
If anyone’s interested, I could provide a simple write-up to install my favorite databases on such a system: so let me know.