It’s excellent that the Spotify music service supports Linux with Snap, Flatpak, and Ubuntu applications, but overall, the app is cumbersome and doesn’t work well on Linux PCs with minimal resources. That’s why Librespot has come on to the scene so that users can listen to Spotify from the Linux terminal.
Install Librespot
Installing Librespot requires installing several build-time dependencies. So, before we can deal with the source code, it’s vital to go over how to get everything needed to compile.
Dependencies for Linux distributions differ slightly, so things may not work 100% of the time. For more guidance on what dependencies you’ll need, check out the developer’s GitHub page.
Debian/Ubuntu
On Debian and Ubuntu, users must install the “build-essential” package, the Rust programming language and the “libasound2-dev” package. You will also need Git to interact with the source code.
sudo apt install build-essential cargo libasound2-dev rust git
Fedora
Fedora users will need to install the ” alsa-lib-devel” package, the “make” package, the “gcc” package and the Rust programming language. You’ll also need to install Git to interact with GitHub.
sudo dnf install alsa-lib-devel cargo make gcc rust git -y
Arch Linux
There are quite a few dependencies to install on Arch Linux to build Librespot. However, lucky for you, the entire program is inside of the Arch Linux AUR, so no effort is necessary. Just follow the commands below to install the dependencies, as well as Librespot on Arch.
First, install the Git and Base-devel packages on Arch Linux with Pacman.
sudo pacman -S git base-devel
Clone the AUR package build of Trizen, to make installing Librespot much quicker.
git clone https://aur.archlinux.org/trizen.git
Move the terminal into the “trizen” folder and build it with makepkg.
cd trizen
makepkg -sri
Use Trizen to install Librespot.
trizen -S librespot-git
Build the software
With all of the dependencies taken care of, clone the source code to your Linux PC using the git clone command.
git clone https://github.com/librespot-org/librespot.git
Move the terminal window into the “librespot” folder with the CD command.
cd librespot
You’ll then be able to build Librespot with the cargo command.
cargo build --release
Once the program is done building, move the built files from the source code folder into a new location in the “opt” directory, using the commands below.
cd librespot/target/release/ mkdir -p /opt/librespot/ sudo mv * /opt/librespot/
Using touch, create a new script to run the software easily.
sudo touch /usr/local/bin/librespot
Open up the script file with Nano.
sudo nano -w /usr/local/bin/librespot
Paste the code below into Nano.
#!/bin/bash
##Librespot runner
cd /opt/librespot/
sudo ./librespot -n "Librespot" -b 320 -c ./cache --enable-volume-normalisation --initial-volume 75 --device-type avr
Save Nano with Ctrl + O, and exit with Ctrl + X. Then, update the script file’s permissions using the chmod command.
sudo chmod +x /usr/local/bin/librespot
sudo chmod 755 /opt/librespot/
You can then start up the Librespot application from your terminal window with:
librespot
Using Librespot
LibreSpot isn’t a terminal app in the sense that it has a full text-based user-interface to use. However, it does work with Spotify connect, so, if your Linux PC can’t handle the amount of RAM that the official Spotify client needs, this is the best alternative, by far.
To use the Librespot application, start by taking out a smartphone and install the Spotify app on it. Once the app is set up, log into your Spotify account. Then, follow the step-by-step instructions below to learn how to play music through Librespot.
Step 1: Go to the Spotify app on your smartphone and tap the search button to find an artist, playlist, album or song to listen to, and tap on it to tell the Spotify application on your smartphone to start playing it.
Step 2: Open up the playback window on the bottom to make it full-screen on your smartphone.
Step 3: Pause the music in the app to stop it from playing, but don’t close the playback window.
Step 4: Look to the bottom left portion of the Spotify app’s playback window for a white icon, and tap it with your finger to bring up the “Spotify Connect” pop-up window. If you can’t find the icon, it looks like a Smartphone/TV logo.
Step 5: After tapping on the Spotify Connect icon, a new window will appear on your smartphone. This window says “Connect to a device,” and will list off your Spotify Connect-enabled devices.
Step 6: Inside of the “Connect to a device” window, tap on the device labeled “Librespot.”
Step 7: Press the play button on the music you previously paused to listen to Spotify through the Linux terminal on your PC!