Spotify music service supports the Linux operating system with the help of Snap, Flatpak, and Ubuntu applications. However, the Spotify app does not work well on Linux PCs that have minimal resources.
Because of this, Librespot has come to the rescue so that users can listen to Spotify from their Linux terminal. This how-to guide will walk you through how to install Librespot and use it to listen to Spotify.
To install Librespot, the user will have to install several build-time dependencies. Dependencies will differ based on the Linux distributions that are used which can be followed below.
For Debian and Ubuntu, you need to 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. Install using the following command:
sudo apt-get install build-essential libasound2-dev
For Fedora users, you will need to install the “alsa-lib-devel” package, the “make” package, the “gcc” package and the Rust programming language. You will also need to install Git to interact with GitHub. Install using the following command:
sudo dnf install alsa-lib-devel make gcc
For Arch Linux users, you will need to install several dependencies, but the good news is that the entire program is inside the Arch Linux AUR. First, you will install the Git and Base-devel packages on Arch with Pacman. Then you will need to clone the AUR package build of Trizen to make Librespot install quicker using Trizen. Follow the commands below to install the dependencies and Librespot on Arch.
sudo pacman -S git base-devel git clone https://aur.archlinux.org/trizen.git cd trizen makepkg -sri trizen -S librespot-git
Building the Software
With all of the dependencies taken care of you will need to use the following commands to clone the source code to your Linux PC using the git clone command. Then you will have to move the terminal window into the “librespot” folder with the CD command and build Librespot with the cargo command. Once the program has completed the build process, you will need to move the created files from the source code folder in a new location in the “opt” directory.
git clone https://github.com/librespot-org/librespot.git cd librespot cargo build --release cd librespot/target/release/ mkdir -p /opt/librespot/ sudo mv * /opt/librespot/
Using touch, you will need to create a new script to run the software quickly, then open the file with Nano.
sudo touch /usr/local/bin/librespot sudo nano -w /usr/local/bin/librespot
The next step is to add the code below into Nano.
#!/bin/bash ##Librespot runner cd /opt/librespot/ sudo ./librespot -n "librespot" -b 320 -c ./cache --enabe-volume-normalisation --initial-volume 75 --device-type avr
Next, save Nano with Ctrl+O, then exit with Ctrl+X. Use the following chmod command to update the script file’s permissions.
sudo chmod +x /usr/local/bin/librespot sudo chmod 755 /opt/librespot/
Then use the following command to start the Librespot application from the terminal window.
Librespot works using Spotify connect. So to use the Librespot application, you will need to have Spotify installed on your smartphone. Once you have the Spotify app installed and set up, login into your account, and follow the following step-by-step instructions to play music through Librespot.
- Within the Spotify app on your smartphone, search for an artist, playlist, album, or song that you want to listen to, then tap play.
- Open the playback window at the bottom of your smartphone screen.
- Pause the music but don’t close the playback window.
- Look in the bottom left corner of the playback window and find the white icon that brings up the “Spotify Connect” window.
- The next window will say, “Connect to a device” and will list all connect-enabled devices.
- You will want to choose the device labeled “Librespot.”
- Press the play button on the app to unpause your music, and Spotify should start playing through the Linux terminal on your PC. Enjoy!