Installing Raspbian and Mopidy on the Raspberry Pi

Posted on Posted in Beginner, Guides, Intermediate, must-read

Over the next few days, we will be adding a Raspberry Pi running Raspbian to our home network. While we could install Volumio on the Pi just like we did previously, I would prefer to instead install Mopidy as our music server. Mopidy is similar to Volumio (they’re both based on MPD – the most popular Linux music player daemon), but Mopidy has an even more active community around it, comes with several different front-ends to chose from, and supports a number of plugins to add additional functions to the player. I will be using the Iris user interface which integrates well with Spotify, looks great, and creates a music experience that I just haven’t been able to beat with any of the other choices that I have tried – including Volumio. Just like Volumio, it will also support airplay out of the box if you have an Apple device that you would like to stream from. It also looks great on mobile without any need for an additional app.

When this is all done, we will have a solid music player. Additionally, we will be able to phase out a few of the existing components; specifically, we will be able to remove the desktop running Volumio and the Control4 radio tuner since neither will be needed moving forward.

The following resources are used or referenced in this guide:

Installing Raspbian

Raspbian is the official operating system for the Raspberry Pi (not that plenty of others can’t be installed, however). As a result, installing Raspbian has been made particularly simple, and you can go about it one of two ways: either by using NOOBS (New Out Of Box Software), an OS manager that allows you to pick from a handful of operating systems, or by downloading Rasbian by itself  and flashing it onto your SD drive. I have chosen the second option since I’m not interested in moving between the OS choices. The Raspbian image comes in two flavors: the OS with all of the normal desktop packages, or a lite version that is command-line only. Since I will be using this Pi in a “headless” setup (no keyboard, no mouse, no monitor), I’ll be choosing the lite version.

As noted by the official Raspbian walkthrough, after downloading the image, you’ll want to download and install Etcher.io in order to turn the downloaded image into a bootable disk that the Pi can read. After installing Etcher, the boot-disk creation process is super simple. Just pick your downloaded image, the removable drive that you want to make bootable, and then click the “Flash!” button. Once the boot-disk is created, you can use it to boot the Pi for the first time. Even though I intend to use the Pi in a headless configuration, I recommend having a keyboard and monitor handy for the first boot (unless you’re a masochist). You’ll need to enable SSH to control the Pi remotely, and since SSH is disabled by default, if you don’t have a display connected for the first boot you’ll be trying to type in commands blindly and hoping that you entered everything correctly.

Enabling SSH

Probably the easiest way to enable SSH is by using the sudo raspi-config command. This will bring up a small user interface allowing you to set a handful of basic options in Raspbian. To enable SSH you will want to select Interfacing Options->SSH and then elect to enable the option. While you’re in here, you may find it beneficial to change a few other options. First, setting a hostname for the device and changing the password might be a quality of life improvement once you’re regularly connecting to the device via SSH. Additionally, under the “advanced options” page, you can set the Raspbian file system to expand to take up the entirety of the bootable drive that you are using. If you don’t plan to dual-boot the Pi, this is likely a suggested change. Lastly, if you intend to have a monitor connected to the Pi permanently, it’s worth noting that audio output will default to the HDMI cable. If you’re following this guide with the intention of using the 3.5mm output jack for sound, you’ll need to set that jack to be the default output under the “audio” setting within the “advanced options” tab.

Once you have changed all of the options in the config that you are interested in, you should probably restart the pi using the command sudo reboot . Now, from a separate computer on your network you will be able to use an SSH client such as PuTTY to connect to your Raspberry. The connection will be a standard SSH connection using the username “pi” and the password “raspberry” (unless you changed it in the config options earlier).

Installing Mopidy

Now for the actual installation of Mopidy. Each of the numbered commands below should be entered separately (without the number, obviously).

First you will need to add Mopidy’s repository GPG key and add the repository to your repository list:

Once you have added the repository, you should update your package list and install Mopidy from the new repository that you have just added. While you’re at it, you should install Python 2’s Pip package manager if you don’t have it already. This will install Python2 which you will need in order to run Mopidy. Additionally, you will use Pip to install Mopidy’s plugins – they’re all written in Python. You’ll also probably want to set Mopidy to automatically run as a service so that you can do other things with your Pi. The last command will start that service.

To confirm that everything worked and that Mopidy is running, you can use the command sudo systemctl status mopidy to check on the status of the Mopidy service. If everything installed correctly, you should see a message similar to that on the left that indicates that the service is active and running. Running the status command will also let you see any errors returned by Mopidy during start up. For example, if you followed this guide, you will probably see an error at this point about setting some configuration values for your local media folder. We have ignored that step for now since the config file used by Mopidy changes depending on whether or not you run Mopidy as a service.

Let’s go ahead and install the other plugins that we might want, first.

Installing Mopidy Plugins

Mopidy has a large number of plugins, most of which are situational depending on what media you might be interested in playing or what media sources you might want to use. All of the plugins are installed using Pip2 and can be found in Mopidy’s documentation. If you’re not interested in reading through the documentation, the following commands will add the Iris interface and a handful of useful media sources that you might be interested in using no matter the specifics of your system. It also adds the gstreamer audio plugins that will enhance your ability to playback different audio formats. Technically, pip2 lets you install multiple packages in the same command, so you can reduce all of these to one installation command, but I had some random issues with packages not installing properly on the first try. Splitting them all up makes it a bit cleaner, in my opinion.

If everything installs properly, we have one last step before everything should be finished: we need to check the configuration file for any other issues that need to be cleaned up (like that local media location error from earlier).

Final Configuration Changes

When being run as a service, the configuration file for Mopidy is located at /etc/mopidy/mopidy.conf and can be opened using the built-in text editor in Rasbian called Nano: sudo nano /etc/mopidy/mopidy.conf. Most of the plugins above will have added sections to the config file, but only a few sections will need to be changed from their defaults. In particular, the [core] section of the config will include a handful of file paths for where different types of files should be stored. The Mopidy configuration documentation recommends a few defaults that seem reasonable, and my revised core section looks like the following:

Additionally, somewhere in your config file, you will find the [local] section which includes a setting for your media_dir. This will also need to be set to a directory on the Pi where you intend to upload your personal media files.

Running Mopidy

After installing all of the above plugins and changing the config settings to match, you should reboot Mopidy’s service using sudo systemctl restart mopidy . After restarting, you can use the status check command from earlier to ensure that Mopidy is properly running and that it didn’t throw any new errors or warnings during the boot process. With any luck, everything should be running properly, and you can finally access Mopidy using your web browser using the IP address of the Pi and port 6680 (for example, 192.168.0.x:6680). This will drop you on a welcome page to Mopidy and allow you to choose between the different front-ends that are installed. If you select Iris, you will get to see that interface, and you can set your bookmarks accordingly to avoid the welcome screen in the future.