Follow these steps to get up and running with a fresh install of Raspbian Lite, all ready for the temperature-machine.
Extras
You may want some optional extras:
May 14, 2019.
In this tutorial, we’re going to build a highly optimized Raspberry Pi system that runs very lean on resources with the help of Raspbian Lite. Whereas a baseline Raspbian system consumes around 158 MB of RAM, Raspbian Lite runs at a mere 34 MB. To achieve this lighter weight footprint, we must give up the graphical user interface (GUI); however, we’ll include steps in the build (and tips) to help us work productively without a GUI.
This guide follows the same flow as my popular Beginner’s Guide to Installing Node.js on a Raspberry Pi, and I recommend that you use that guide if you are a beginner or if you simply want the luxury of using a GUI. There’s nothing wrong with that, and a GUI makes sense in many contexts! For those who want to run a lighter weight Pi system, let’s get started!
Raspbian X DownloadTable of ContentsHardware Needed
If you don’t currently own a Raspberry Pi, the easiest way to get started is to buy a starter kit such as this one on Amazon:
We’ll need the following items to get started:
Once you have gathered the needed hardware, we are ready to bring our Pi machine to life!
Write Raspbian Image to SD Card
We will be running Raspbian Lite which is a free operating system based on Debian Linux and optimized for the Pi. Here we go:
Prep the Hardware
See the Raspberry Pi 4 Tech Specs page for a diagram showing the various parts of the Pi 4. Also, you will find a diagram of the Pi 2 here (the Pi 3 looks very similar). These diagrams may help you in this section. Let’s get this little SBC (single board computer) ready to boot! Here are the steps:
Option for advanced users – Complete initial setup without a monitor and keyboard
We are ultimately creating a Raspberry Pi system that can run in headless mode (i.e. without a monitor and keyboard). It is possible to even complete the initial setup without a monitor and keyboard. To accomplish this goal, you will need to create the following files in the root of the microSD card on your PC/Mac after writing the Raspbian image.
Thanks to Graham Smith who pointed out this option in the comments!
After connecting the power cord and booting, you will need to find the Raspberry Pi on your network so you can remote in using ssh. Use the ping command to locate your system on the network. The following may work:
If this does not work, you can use either the Adafruit Pi finder or nmap to find the Pi’s IP address so you can remote in. Later in this tutorial, we install Samba so finding your Pi on the network will no longer be a concern.
Configure the Pi
Log in to your new system when you are prompted using the following credentials:
We first need to make a few changes to the Pi for optimization, and to personalize it for our use. To get started, run the following command:
This will launch the following screen:
At this screen, we will configure our Pi. To navigate, there are a few keyboard shortcuts we need to know:
Who needs a mouse when you have a keyboard? ? Let’s start configuring!
Change User Password (Optional, but recommended)
From a security perspective, it’s a good idea to change the default password. Just make sure you don’t forget it. ?
To change your password:
Network Options
Arrow down to Network Options and hit the Enter key.
Hostname
If you prefer less typing, you can change the host name from “raspberrypi” to something shorter such as “raspi”.
Wi-fi
You definitely want to configure your wi-fi now so you can remote into your Raspberry Pi over the network when it is rebooted, and you no longer have the keyboard/mouse/and monitor connected to it.
Raspbian Stretch Lite Install
Arrow back down to Network Options and hit Enter.
Arrow down to Wi-fi and hit Enter.
Follow the prompts to enter the following information:
Localisation Options
The Raspberry Pi is the brilliant brainchild from our friends in the UK. If you are not from the UK, some of the keys on your keyboard may not work as expected. Here are the changes I made to make my Pi feel at home in San Diego:
First, arrow down to Localisation Options and hit Enter.
Change locale – hit Enter (the screen will momentarily blip to black before returning to raspi-config.)
Arrow back down to Localisation Options and hit Enter.
Change Timezone – hit Enter
Arrow back down to Localisation Options and hit Enter.
Change Keyboard Layout – hit Enter
Arrow back down to Localisation Options and hit Enter.
Change Wi-fi Country – hit Enter
Raspbian Stretch Lite Mac Download CnetInterfacing Options
We want to enable the SSH server so we can remote into our system without dedicating a monitor, keyboard, and mouse to it. Here are the steps:
Advanced Options
Back at the raspi-config main menu, arrow down to Advanced Options and hit the Enter key.
We will be running our Raspbian Lite system without a graphical user interface so we can reduce the amount of memory made available for the GPU and consequently make more memory available for the CPU since the CPU/GPU memory is shared.
Arrow down to Memory Split and hit the Enter key.
Enter a value of 16 for the amount of memory in MB that the GPU should have and hit the Enter key.
Once you are back to the main menu (as shown in our raspi-config screenshot above), you can hit the Tab key, arrow right to select the <Finish> option, and hit the Enter key. The Pi will then let you know that it needs to reboot to activate the changes you made. Reboot it now and log back in.
We’re now ready to move on and ensure our system is up to date with security patches.
Apply Raspbian Updates
First, let’s verify that our Wi-Fi has been configured correctly and that we have Internet access. Issue the following command from the terminal:
You should receive responses back from google.com if you have Internet connectivity. If not, you will need to repeat the Wi-Fi configuration steps outlined earlier in the tutorial and test again.
Assuming you have Wi-Fi connectivity, you are ready for the next steps.
We will first run the apt “update” command. This command will not actually update any software on the system but will download the latest package lists from the software repositories so that Raspbian will be aware of all new software available along with dependencies. Issue the following command at the “$” prompt:
Next, run the following command to upgrade any packages installed on your system that need upgrades:
This is important to keep your Pi system synchronized with security updates, etc. These two commands should be issued together and run periodically.
Prepare for Remote Connection
We want to run our Pi remotely without requiring a dedicated HDMI monitor and USB keyboard/mouse. This is known as headless mode.
In the steps above, we enabled the SSH server, and now we need to install the samba package so we will be able to access the Pi by its host name from Windows machines on the network rather than by its IP address which can change since the Pi receives its IP address via DHCP. (For OS X users, you can install Bonjour and then access your Raspberry Pi by host name. For example, if your host name is “raspi”, you can access it on OS X as “raspi.local”.) OK, let’s install Samba:
After this installation completes, you should be able to ping the Pi Hostname (configured in Raspberry Pi Configuration program above) from a Windows machine:
You are now ready to launch a remote connection!
Amazing! We are connected remotely to the Pi and we no longer need the dedicated HDMI monitor and USB keyboard/mouse. Let’s go ahead and shut down the Pi for a minute so we can free up our monitor and keyboard/mouse:
Create Windows File Share on the Pi (Optional)
We can create a Windows file share on the Pi so that we can copy files from our Windows machine directly onto the Pi. This can come in handy in many contexts. This is also useful for OS X users since you will be able to connect to your Raspberry Pi file share from Finder under “Shared”. Here’s how we do it:
We are ready to connect to our newly created Pi file share from Windows!
Install Node.js (Optional)
You now have an amazing general purpose Raspberry Pi system that can be used for a variety of tasks and inter-operates well in the Windows world (it even looks like a Windows machine to the other Windows machines!) – and can play nicely in the Mac and Linux world too. Let’s go ahead and install Node.js so we will be ready to do some fun projects in the future. Here are the steps:
Our friends at NodeSource host and maintain some excellent Node.js binary distributions. We will leverage a command they have written to add another package repository to our Pi so that we will be able to “apt install” a modern version of Node.js from their repository. This is beneficial since the Debian/Raspbian versions may not always be up to date. By adding the NodeSource repository, we will also be able to receive updates rather than just installing a standalone (.deb) file version of Node that cannot be updated easily.
Note: As described at the beginning of this article, this final section of the tutorial related to the installation of Node.js requires a Pi system based on the newer ARMv7 or ARMv8 chip such as the Pi 4/Pi 3/Pi 2. NodeSource provides Node.js binaries for these newer ARMv7+ architectures, but not for Raspberry Pi systems based on the older ARMv6 architecture such as the Raspberry Pi Model B/B+ or the Raspberry Pi Zero.
Read the writing carefully on your Raspberry Pi circuit board to confirm it indicates something like “Raspberry Pi 4 Model B” or “Raspberry Pi 2 Model B”. If in doubt, run the following command in the terminal:
![]()
If the result returned starts with “armv6”, you are running a Raspberry Pi based on the older ARMv6 chipset and the next Node.js installation step will not work; otherwise, you are ready for the next step.
Here we go in the final stretch! Let’s proceed with an installation of the latest version of Node at the moment which is Node 14.13.0.
The previous command updates our Debian apt package repository to include the NodeSource packages.
Note: It’s generally a good idea from a security perspective to know what commands you are invoking on your system, especially since the command above invokes the script as the root user. If you want the technical details behind this script, you can launch the URL (https://deb.nodesource.com/setup_14.x) in your browser and review the code. The script carries out some ceremony to determine the Linux distribution you are running and instructs the Debian apt package system to add the NodeSource package repository as a trusted source for obtaining Debian packages. This enables us to install Node.js now and upgrade to more recent versions of Node.js when they become available.
Now that we have added the NodeSource package repository, we can move on and install Node.js!
We can then test and see what version of Node we are running and launch the Node REPL as we discussed in the previous article as a quick test to confirm the installation was successful.
Raspbian Lite Workflow
We have created a lean Raspberry Pi system without a GUI, but we don’t want to hinder our productivity when we need more than the command-line and text-based editors such as nano can provide us. If you have followed the steps above and created the Samba file share and mapped a drive, you are good to go!
Here’s a typical workflow that will improve your productivity. In this example, we assume you have mapped the “P drive” to your Raspberry Pi.
To improve your workflow in the terminal, I recommend installing and learning about tmux. The tmux application allows you to multiplex and access multiple separate terminal sessions inside a single terminal window or remote terminal session. The lower tech alternative is to simply launch multiple Putty sessions, but this is less elegant. See this tmux tutorial if you want to learn more.
Additional Optimizations (Optional)
We can save approximately 25 mA of power (according to Jeff Geerling) by powering down the HDMI display circuitry—assuming you are planning to remote in and will not connecting an external monitor to the Raspberry Pi HDMI port. We will run a command when the Pi boots to accomplish this goal.
Conclusion
Congratulations! You have built a lean Raspberry Pi system that is well suited for creating and implementing a wide variety of fun projects. You are equipped and ready to make something awesome!
Follow @thisDaveJ (Dave Johnson) on Twitter to stay up to date on the latest tutorials and tech articles.
Related Articles![]()
Beginner’s Guide to Installing Node.js on a Raspberry Pi
Using Visual Studio Code with a Raspberry Pi (Raspbian) Upgrading to more recent versions of Node.js on the Raspberry Pi Debian apt command cheat sheet – summary of new apt Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |