How to Create Your Own Spotify Enabled Music Server on the Raspberry Pi with Mopidy

by | May 25, 2018 | Audiophile, Technology

Having a nice home music server is definitely a bonus for anyone who has a music collection. This guide will show you how to set up a home music player with Spotify on the Raspberry Pi using Mopidy. Mopidy is a Music Server which also has many other extensions. This guide will help you set up your local library and Spotify, but you can also add Google Play Music, Sound Cloud and many others as well!

First lets get a copy of Raspian Lite.  At the time of writing this, we are using Raspian Stretch lite.  You can download a copy of Stretch here.

Once downloaded, go through the initial setup with

[sourcecode language=”shell”]sudo raspi-config[/sourcecode]

and set your default password, locale, etc.  Once your initial config is completed, lets get started configuring.

Lets update our Raspberry PI

Run each of these commands one by one:

[sourcecode language=”shell”]sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get rpi-update
sudo reboot[/sourcecode]

These commands will update our Raspberry Pi to the latest software currently available.  Each one of these commands will take a little time to complete.

Next, lets install a nice light desktop environment

For simplicity, lets install a desktop environment.  XFCE is lightweight, includes Pulse-Audio and will simplify some of our automation tasks.  If you use a DAC or multiple audio outputs, Pulse-Audio will make things much easier.

[sourcecode language=”shell”]sudo apt-get update
sudo apt-get install xfce4[/sourcecode]

Lets also install xscreensaver, so we can ensure no processor heavy screen saver will come up while idle.

[sourcecode language=”shell”]sudo apt-get install xscreensaver[/sourcecode]

And finally, we want to have the Raspberry Pi automatically log into the desktop environment.

[sourcecode language=”shell”]sudo raspi-config[/sourcecode]

Now head to:

3 Boot Options
B1 Desktop / CLI
B4 Desktop Autologin

This will log us directly into XFCE on reboot.  Now go to <Finish> and select Yes when prompted to Reboot.

Lets configure XFCE

Now we should have rebooted into XFCE.  You will be prompted for a Panel layout.  Select Default.  Next, lets configure our screen saver.  Go to:

Applications (top left)
Under Mode, select Blank Screen Only

Lets install Mopidy

Now, lets install Mopidy.  We can do this by opening a terminal window or by connecting via SSH.  To open a terminal window, go to:

Applications (top left)

Now lets add Mopidy’s GPG Key, Repository, and install.

[sourcecode language=”shell”]wget -q -O – | sudo apt-key add –
sudo wget -q -O /etc/apt/sources.list.d/mopidy.list
sudo apt-get update
sudo apt-get install mopidy[/sourcecode]

In addition, lets add Spotify support, and sqlite support as well for Album covers, etc.

[sourcecode language=”shell”]sudo apt-get install mopidy-spotify
sudo apt-get install mopidy-local-sqlite[/sourcecode]

Next lets install our web interface

[sourcecode language=”shell”]sudo apt-get install python-pip
pip install Mopidy-Iris[/sourcecode]

Now if there were no errors we should have Mopidy Installed.

Lets Configure Mopidy

First we need to create our Mopidy configuration file.  We can do this by starting Mopidy for the first time.

[sourcecode language=”shell”]mopidy[/sourcecode]

This will launch Mopidy and create a default configuration file.  Now to stop Mopidy Press CTRL + C

Now lets edit our configuration file.

[sourcecode language=”shell”]sudo nano ~/.config/mopidy/mopidy.conf[/sourcecode]

Scroll down and make the following changes in the configuration file. The sections to modify will be in the square brackets, the modification will show the default and what you need to change the option to.

#enabled = true TO enabled = false

#hostname = TO hostname = (your current ip address)

#enabled = true TO enabled = false

#library = json TO library = sqlite

#country = NZ TO country = (Your two digit country code)
#locale = en_NZ TO locale = (Your two digit language preference)_(Your two digit country code)

Now for Spotify we need to log into our account and get a client_id and client_secret code for authentication to our account.

Head on over to to get the authorization information.  As stated earlier, this does require you to have a Spotify Premium account.

#username = TO username = (Your username)
#password = TO password = (Your password)
#client_id = TO client_id = (Your client id)
#client_secret = TO client_secret = (Your client secret)
#bitrate = TO bitrate = 320
#toplist_countries = TO toplist_countries = (Two digit country code of countries you would like seperated by comma’s)

Optionally, if you would also like to add your local or network music files change the following

#media_dirs = TO media_dirs = (Location of your music files)

This location can be on your Raspberry Pi, or a network location if it has been mounted to your system.

This should be enough to get us started.  Press CTRL + X, then press Y to confirm save, and Enter to save the file.

Lets set Mopidy to AutoStart

Back on our desktop, lets add Mopidy to autostart with our Raspberry Pi.  Do this by going to:

Session and Startup
Go to the Application Autostart Tab
Click the +Add button
Name: Mopidy
Description: Mopidy Music Server

Now click the browse button to browse for the Mopidy program.  Next click on:

File System (Left)

Now click Okay, then Close.  Mopidy will now autostart with XFCE under the pi user.  Lets give a reboot and test to see if things are working.

[sourcecode language=”shell”]sudo reboot[/sourcecode]

Lets Connect to our new Mopidy server

Next lets test to make sure we are up and running.  Open your web browser on phone/tablet/desktop and enter in the following URL:


If all went according to plan you should be greeted by a nice looking interface. If your on your smart phone, you can add this to your home screen and have a nice new icon for your music server!