Turn your Raspberry Pi into a Spotify server

In this tutorial we will install Mopidy on our Raspberry Pi. This will allow us to use the Pi as a music server where we can access all of our local music files, as well as playlists from e.g. Spotify, and stream it directly to our TV or speaker system.

What is Mopidy?

Mopidy is a music server that can play music from a wide variety of sources, like your local hard drive, radio streams, Spotify, and SoundCloud. The nice thing about Mopidy is that it collects all of your music sources in one place. This makes it a perfect match for our Raspberry Pi.

Another cool feature is that when you search your library, it combines results from all music sources, and you can mix tracks from all sources in your play queue. That includes your playlists from e.g. Spotify, SoundCloud, or other available sources.

To control your Mopidy music server, you can use a wide variety of web clients, the Ubuntu Sound Menu, any device on the same network which can control UPnP MediaRenderers, or any MPD client.

There are MPD clients available for many platforms, including Windows, OSX, Linux, Android and iOS. We will look into some of these in the end of this article.

Using these clients, Mopidy allows you to control your music from any device. And if you make your Pi accessible from outside the LAN, you can literally control your music from anywhere in the world! 


0. Add needed modules

As a first step we need to activate some modules to avoid potential problems during the installation. First, run the following command to activate ipv6:

sudo modprobe ipv6

Now open /etc/modules and add this to make sure modules are loaded on reboot:


1. Add the archive’s GPG key

Run the following command to add Mopidy’s GPG key:

wget -q -O - http://apt.mopidy.com/mopidy.gpg | sudo apt-key add -

2. Modify your sources.list

Add the following to /etc/apt/sources.list, or if you have the directory/etc/apt/sources.list.d/, add it to a file called mopidy.list in that directory:

# Mopidy APT archive
deb http://apt.mopidy.com/ stable main contrib non-free
deb-src http://apt.mopidy.com/ stable main contrib non-free

3. Install Mopidy and all dependencies:

sudo apt-get update
sudo apt-get install mopidy

4. Create the Mopidy config file

Now that we have installed Mopidy, it’s time to make some modifications to its config file. Right now we don’t have a config file, and we can either create on manually, or let Mopidy generate one for us that will contain all the default values. We are not stupid, so let’s do the latter.

In order to have Mopidy create the config file for us, we simply have to start Mopidy. If it cannot find a config file, it will create a new one at startup. The file will be created in ~/.config/mopidy/mopidy.conf.

Run Mopidy:


…and you should see something like this:

 INFO Starting Mopidy 0.18.3
INFO Loading config from: builtin defaults, /etc/xdg/mopidy/mopidy.conf, /home/pi/.config/mopidy/mopidy.conf, command line options
INFO Enabled extensions: mpd, http, stream
INFO Disabled extensions: local
WARNING Found local configuration errors, the extension has been automatically disabled:
WARNING local/media_dir must be set.
WARNING Please fix the extension configuration errors or disable the extensions to silence these messages.
INFO Starting Mopidy audio
INFO Starting Mopidy backends: StreamBackend
INFO Audio output set to "autoaudiosink"
INFO Audio mixer is using software mixing
INFO Starting Mopidy core
INFO Starting Mopidy frontends: HttpFrontend, MpdFrontend
INFO MPD server running at [::ffff:]:6600
INFO HTTP server running at

Stop the server with Ctrl-C.

Now we have the configuration file in place. If you want to, you can take a look at it to see how the default settings are. We will edit a few things later on. 

6. Restart the system

Now we need to restart the system to make sure all the new modules and dependencies are working correctly:

sudo reboot
A very important note for RaspBMC users. Due to a dependency version problem that is caused when installing Mopidy, you might have to make some minor configurations for XBMC to start properly (this depends on your system’s version).

If you notice that XBMC is not starting but gets stuck in a loop, you need to make these configurations. In short, what you have to do is the following:

Run the following command, and it should stop the loop and start up as normal:

sudo ln -sf /home/pi/.xbmc-current/xbmc-bin/lib/xbmc/system/libtag.so.1 /usr/lib/arm-linux-gnueabihf/libtag.so.1

Then you need to open /etc/rc.local and add the command to the end of the file to make it persistent on reboot. Now it will not complain anymore when you restart your system.

You can read more about it in this post.

7. Audio output

Once you have restarted the system, we can start making some changes to our settings.

By default the audio will output to HDMI, and if you want to change that we need to change this value in the amixer settings:

sudo amixer cset numid=3 1

The ‘1’ in the end indicates that we want the audio to output to analog. Other options for this value are:


You can test these settings by running:

aplay /usr/share/sounds/alsa/Front_Center.wav

… and you should hear a voice saying ‘front center’.

8. Install Spotify extension

After all the basic settings for Mopidy are in place, we can install the Spotify extension. This will allow Mopidy to connect to Spotify with your account and fetch all your playlists. Run the following command to install the extension:

sudo apt-get install mopidy-spotify

9. Edit the Mopidy conf

Now it’s time to make some modifications to the config file. Let’s open the  ~/.config/mopidy/mopidy.conf file again so we can add a few things.

Under the section [ audio], we need to change the output value:

[ audio]
output = alsasink

Remember to remove the ‘#’ from the beginning of the line. You can leave all the other values as they are.

We also have to add a new section for the Spotify extension. Add the following anywhere in the file:

username = yourusername
password = yourpassword

Next we will prepare Mopidy to accept client connections. Under the section [mpd], change hostname to :: and set a password:

hostname = ::
password = yourpassword

The change in hostname makes it possible for us to connect to Mopidy from any IP address, and not only from the Pi itself.

Leave the rest as default.

When you have done this we must restart Mopidy in order for it to load the new settings:

sudo pkill mopidy

Now you can see that Mopidy is also loading the Spotify extension, and you should also see that it’s loading all of your Spotify playlists.


Now that we’ve installed Mopidy, we can start playing around with different clients we want to use to connect to it. At this point you can connect any MPD client to Mopidy and control your music. There are a few you can choose from, and the official Mopidy site lists a few they recommend.

MPD Client

We have already prepared Mopidy to accept connections from MPD clients, so let’s start with that.

If you have an Android phone, you can download MPDroid from here.

iPhone users can download MPoD from here.

In order to connect to your Mopidy server, make sure that your phone is connected to the LAN and simply input the IP of the Pi along with the password you set for the mpd connection in the Mopidy config.

Web client

You might want the option to connect to Mopidy through a web client, so let’s set that up as well. This means anybody can access it from a browser, which is nice if you have friends over and they want to search for a song from their phone or laptop.

There are a few HTTP clients for Mopidy that work really great. We will install Mopidy-Webclient by woutervanwijk, but you can use anyone you’d like.

Let’s get the client:

sudo mkdir -p /opt/webclient
wget https://github.com/woutervanwijk/Mopidy-Webclient/archive/master.zip
unzip master.zip
sudo mv Mopidy-Webclient-master/flatclient/ /opt/webclient/
If you have problems getting the zip file due to an error like:

ERROR: The certificate of `github.com' is not trusted.

Add the --no-check-certificate flag to the wget command

Now we need to edit the Mopidy config file:

vim .config/mopidy/mopidy.conf

Find the [http] section, and edit it to look like this:

enabled = true
hostname = ::
port = 6680
static_dir = /opt/webclient/flatclient

Restart Mopidy:

pkill mopidy

Now you are able to connect to Mopidy through your browser. Simply enter the IP of you Pi, and the port as specified in the config file (6680), e.g.

This was a rather long tutorial, but hopefully it was worth it. Don’t forget to share it if you liked it, and drop a comment if you have any question or need help with anything!

Share this Story

About Robin Bellini Olsson

Software engineer, big thinker, and co-founder of Noeit.
Political views: Android > iOS


  1. Hey there, thanks for a great tutorial! I’m interested in setting this up, with the audio outputted on the analog jack. If that happens, does Raspbmc itself still use HDMI audio? I.e. is it possible to simultaneously transmit Mopidy audio via the analog, while playing back something in Raspbmc itself over HDMI?

    Conversely, if you DON’T change Mopidy to use analog and stick with HDMI, then what takes priority, Mopidy audio or Raspbmc audio?

    What I’d like to do is use Mopidy with Spotify as a background audio player, but I want to still be able to use Raspbmc to output video and audio content over HDMI, without needing to constantly switch between analog and HDMI in Settings.


    • Hi David, thanks for the feedback!

      That’s a great question. When you set the amixer to use output 1 (analog) you’re setting this for Mopidy, which means XBMC should still output audio from videos etc through HDMI (if you haven’t changed it).

      You can make sure that XBMC is using HDMI for audio output under Settings->System->Audio Output. Check that ‘Audio output device’ is set to HDMI and you should be good to go. These are the setting I’m using, and I output Mopidy over analog and videos over HDMI.

      Hope it helps!

  2. Hello,

    i followed all your steps excepting the spotify plugin Installation, but it want work for me. I’m using a Raspberry Pi B+ with the newest Raspbian but when I try to connect my iPhone 5 with MPoD App I can’t find my Pi automatic and would not connect when I try to add it manually.

    Do you have any ideas about this?

    best regards

  3. Thank you so much for this awesome tutorial, it’s very well made! After a long struggle getting mopidy and xbmc working on the same install, I finally found your tutorial and setup was a breeze! I almost threw the raspberry out the window out of frustration :)

  4. Great tutorial. Great job. Thank you so much for this step-by-step

  5. Hello and thank you very much for this awesome tutorial. I am a newbie and i stuck in to things:

    Firstly, when i restart Mopidy in order for it to load the new settings, it stucks on the point when spotify loads the playlists.

    Secondly, when i get the client the following happens:

    @raspbmc:~$ sudo mv Mopidy-Webclient-master/flatclient/ /opt/webclient/
    mv: cannot stat `Mopidy-Webclient-master/flatclient/': No such file or directory

    Any help would be appreciated.

  6. I am getting an error after editing the config file for the last time. Running mopidy I get this: “Front end initialization error: HTTP server startup failed Address already in use”

  7. Hi Mr Bellini!
    I have this weird problem:
    Installed , following your tutorial, modipy and spotify.
    BUT hen i launch the prog, this is the result:

    WARNING /home/pi/.config/mopidy/mopidy.conf does not have a config section, not loaded.

    These seem to be no errors, so tihs is the config file:

    pi@raspbmc:~$ ls -l /home/pi/.config/mopidy/mopidy.conf
    -rw-r–r– 1 pi pi 1808 May 6 10:36 /home/pi/.config/mopidy/mopidy.conf

    pi@raspbmc:~$ cat /home/pi/.config/mopidy/mopidy.conf
    !# For further information about options in this file see:
    # http://docs.mopidy.com/
    # The initial commented out values reflect the defaults as of:
    # Mopidy 1.0.4
    # Mopidy-HTTP 1.0.4
    # Mopidy-Local 1.0.4
    # Mopidy-M3U 1.0.4
    # Mopidy-MPD 1.0.4
    # Mopidy-SoftwareMixer 1.0.4
    # Mopidy-Stream 1.0.4
    # Available options and defaults might have changed since then,
    # run `mopidy config` to see the current effective config and
    # `mopidy –version` to check the current version.

    #color = true
    #console_format = %(levelname)-8s %(message)s
    #debug_format = %(levelname)-8s %(asctime)s [%(process)d:%(threadName)s] %(name)s\n %(message)s
    #debug_file = mopidy.log
    #config_file =

    #mixer = software
    #mixer_volume =
    output = autoaudiosink

    #scheme =
    #hostname =
    #port =
    #username =
    #password =

    enabled = true
    hostname = ::
    port = 6600
    password = xxxx
    max_connections = 20
    connection_timeout = 60
    zeroconf = Mopidy MPD server on $hostname
    #command_blacklist =
    # listall
    # listallinfo

    enabled = true
    hostname = ::
    port = 6680
    static_dir =
    zeroconf = Mopidy HTTP server on $hostname

    #enabled = true
    #protocols =
    # file
    # http
    # https
    # mms
    # rtmp
    # rtmps
    # rtsp
    #metadata_blacklist =
    #timeout = 5000

    enabled = true
    username = xxxx
    password = xxxxx
    bitrate = 320
    timeout = 10
    cache_dir = $XDG_CACHE_DIR/mopidy/spotify

    #enabled = true
    #playlists_dir = $XDG_DATA_DIR/mopidy/m3u

    #enabled = true

    #enabled = true
    #library = json
    #media_dir = $XDG_MUSIC_DIR
    #data_dir = $XDG_DATA_DIR/mopidy/local
    #scan_timeout = 1000
    #scan_flush_threshold = 1000
    #scan_follow_symlinks = false
    #excluded_file_extensions =
    # .directory
    # .html
    # .jpeg
    # .jpg
    # .log
    # .nfo
    # .png
    # .txt

    where did I go wrong??



    • Hi Stefano,

      It sounds like a permission issue, but looking at the permissions of your conf file, it seems fine. What else does it print except for that warning? Make sure you don’t have any incorrect values in the config

  8. Apart from all the positive stuff above – bah, forcing people to use IPv6? Sounds like something Microsoft would do (look up disabling IPv6 in Windows for security and compatibility purposes)!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2014 Noeit - All Rights Reserved.