Music Player Daemon

From ArchWiki
Revision as of 21:24, 22 March 2012 by K2s (talk | contribs) (Local Configuration (per user) - ~/.mpd/mpd.conf is wrong, it should be ~/.mpdconf as in Rasi's script)
Jump to navigation Jump to search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end


Install mpd, available in the Official Repositories.


MPD is able to run globally (settings apply to all users), locally (per user settings), and in multiple instances. The way of setting up mpd depends on the way it is supposed to be used. A local configuration may prove more useful on a desktop system than on a system that is used by several people simultaneously.

For a comfortable use, it is sensible to provide MPD access to the following files and directories:

mpd.db    # The music database   # The file where mpd stores its process ID
mpd.log   # mpd logs here
mpdstate  # mpd's current state is noted here
playlists # the folder where playlists are saved into

In order for MPD to be able to play back audio, ALSA or PulseAudio needs to be setup and working.

Global Configuration

Note: For a user-specific permissions, change the "user" line above to reflect one of the system users.
Warning: Users making use of PulseAudio will not be able to correctly use mpd when the daemon is set to run as its own user!

MPD comes with an example configuration file, available at /usr/share/mpd/mpd.conf.example. This file holds an abundance of information on MPD configuration, and holds default mixer values.

  • As root, copy this example file to /etc/mpd.conf.
cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf

Editing mpd.conf

The default Arch install keeps the setup in /var and uses "mpd" as default user.

Edit /etc/mpd.conf to reflect as such:

music_directory       "/home/user/music"
playlist_directory    "/var/lib/mpd/playlists"
db_file               "/var/lib/mpd/mpd.db"
log_file              "/var/log/mpd/mpd.log"
pid_file              "/var/run/mpd/"
state_file            "/var/lib/mpd/mpdstate"
user                  "mpd"
# bind_to_address       ""
# port                  "6600"
  • To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:
mixer_type			"software"
  • Users of PulseAudio will need to make the following modification:
audio_output {
        type                    "pulse"
        name                    "pulse audio"
Music directory
  • MPD needs to have +x permissions on all parent directories to the music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home directories to 1700 drwx------. Thus users will most likely need to remount the music directory under a directory that mpd has access to -- this only applies if running as the 'mpd' user.
# mkdir /var/lib/mpd/music
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab
# mount -a
# rc.d restart mpd

See also the forum thread.

  • Another simpler solution would be to just create a symbolic link into /var/lib/mpd/music.
# mkdir /var/lib/mpd/music
# ln -s MUSIC_FOLDER /var/lib/mpd/music/
# rc.d restart mpd

If the music collection is contained under multiple directories, create symbolic links under the main music directory in /var/lib/mpd. Remember to set permissions accordingly on the directories being linked.

Creating the required files

Now, having finished configuring MPD, the files and directories for MPD to write in need to be created:

  • As root, create the directories and files specified in /etc/mpd.conf:
# mkdir -p /var/lib/mpd/playlists /var/run/mpd
# touch /var/lib/mpd/{mpd.db,mpdstate} /var/run/mpd/
  • Change the file's permissions so that the daemon can modify them.
# chown -R mpd /var/lib/mpd /var/run/mpd

Create database

Creating the database is now accomplished via the update feature of the client, for example mpc update.

Note: Creating the MPD database as root using # mpd --create-db is deprecated.

Timeline of MPD startup

To depict when MPD drops its superuser privileges and assumes those of the user set in the configuration, the timeline of a normal MPD startup is listed here:

  1. MPD is started on boot by /etc/rc.conf, by including it in the DAEMONS array. (Or, this can be done manually each session by running rc.d start mpd with root privileges).
  2. Since MPD is now started as root, it first reads the /etc/mpd.conf file.
  3. MPD reads the user variable in the /etc/mpd.conf file, and changes from root to this user.
  4. MPD then reads the contents of the /etc/mpd.conf file and configures itself accordingly.

Notice that MPD changes the running user from root to the one named in the /etc/mpd.conf file. This way, uses of ~ in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of ~ to /home/username to avoid any confusion over this aspect of MPD's behavior.

Local Configuration (per user)

MPD does not need to be run globally as a daemon and can rather work per user. The usual method to configure MPD globally is because the listed files and folders in the default configuration file point to directories owned by root (the /var directory). A less used (but perhaps more sensible) method is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has the benefits of:

  • A single directory ~/.mpd (or any other directory under /home/username) that will contain all the MPD configuration files.
  • Easier to avoid unforeseen read/write permission errors.
Note: This approach will not work with multiple users to having access to MPD at the same time.
  • Begin the setup by creating a directory for the required files and the playlists:
mkdir -p ~/.mpd/playlists
  • Copy the contents of the default MPD configuration file in /usr/share/mpd/mpd.conf.example to the target user's home directory:
cp /usr/share/mpd/mpd.conf.example ~/.mpdconf
  • Create all of the requisite files:
touch ~/.mpd/{mpd.db,mpd.log,,mpdstate}
  • Edit ~/.mpdconf to specify these files:
music_directory    "/home/USER/music"            # Keep commented if your XDG directory already points to it
playlist_directory "/home/USER/.mpd/playlists"
db_file            "/home/USER/.mpd/mpd.db"
log_file           "/home/USER/.mpd/mpd.log"
pid_file           "/home/USER/.mpd/"
state_file         "/home/USER/.mpd/mpdstate"
  • MPD can now be started by typing mpd on the command line.

To have MPD start with the X server add it to ~/.xinitrc or create a .desktop if using a common desktop and save it to ~/.config/autostart/mpd.desktop:

[Desktop Entry]
Name=Music Player Daemon

Scripted Configuration

Rasi has written a script that will create the proper directory structure, configuration files and prompt for the location of the user's Music directory; it can be downloaded here.

Multi-mpd setup

Useful if running an icecast server.

For a second MPD (e.g., with icecast output to share music over the network) using the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., /home/username/.mpd/config-icecast), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., mpd-icecast.log, mpd-icecast.error, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd would use the same music collection as the first one e.g., creating and editing a playlist under the first daemon would affect the second daemon as well. Users do not have to create the same playlists all over again for the second daemon. Call this second daemon the same way from ~/.xinitrc above. (Just be sure to have a different port number, so as to not conflict with the first mpd daemon).


A separate client is needed to control mpd. Popular options are:


  • mpc — Simple KISS client. All basic functionality available || mpc
  • ncmpc — A NCurses client for mpd || ncmpc
  • ncmpcpp — An almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine) || ncmpcpp
  • pms — Highly configurable and accessible ncurses client || pmusAUR


  • Ario — A very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox || ario
  • QmpdClient — A GUI client written with Qt 4.x || qmpdclient
  • Sonata — An elegant Python GTK+ client || sonata
  • gmpc — GNOME Client || gmpc
  • Dpmc — Dmenu-based MPC client with a playlist manager and state-saving on playlist changes || dmpcAUR


  • Patchfork — web client for MPD written in PHP and Ajax || patchfork-gitAUR.

See a long list of clients at the mpd wiki.

External links