Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up --- Bug Reports --- Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news


Author Topic: Guide to getting MAME up and running in linux  (Read 9399 times)

0 Members and 1 Guest are viewing this topic.


  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 51
  • Last login:November 24, 2018, 07:42:36 am
Guide to getting MAME up and running in linux
« on: December 21, 2017, 12:14:44 am »
A few years ago I was looking for instructions on how to properly get MAME running in Linux, and most of the information out there is incomplete, out of date, or just difficult to find.  I spent a lot of my time simply having to research individual parts of the process, because there wasnít a single walkthrough on getting everything up and running.

As I went along, I decided to document the process to hopefully make it easier for myself and other.  Unfortunately, I lost the instructions I originally wrote up, and didnít have a lot of desire to go through the entire process again to try to cover every step reasonably thoroughly.

I wrote up my original instructions with Ubuntu 14.04, and MAME 0.16x (donít remember the exact revision), and was looking at whether or not I wanted to upgrade my MAME machine to 16.04 (yeah, I know, 18.04 is just a few months away,) so I figured this was a good of a time as any to rewrite the instructions.

What these instructions will do for you
After following these instructions, you should have a reasonably lightweight OS running with MAME and a frontend.  The system will be reasonably static, so there should be no need to update anything unless youíre looking to utilize a new feature.  Booting the computer will bring you straight into your frontend, with no need to login, or launch anything manually.

Why linux?
I spent some time looking at various ways to make the mame machine as lightweight and maintenance free as possible, while still being reasonably easy to implement.  My choice came down between taking Windows XP and stripping it down to its bare bones, or starting with a fairly barebones Linux OS and adding what I wanted to actually use.  Philosophically, linux worked better for me.

Why Ubuntu Server LTS?
I mentioned lightweight, yes, there are far more lightweight ways to go than Ubuntu Server LTS, but I was looking at the tradeoff of lightweight, ease of use, and broad base of support.  My first exposure to Linux was Debian, and I like the package management system.  I find that Ubuntu is more user friendly than straight Debian, and the server versions are still relatively lightweight.  The desktop versions of Ubuntu have far more unneeded stuff built in, and actively tries to keep you from doing things that they donít think the average user should be doing, so rather than battling against the intended purpose of the desktop version, Iíd rather build on top of the server version.

These instructions are specifically for installing MAME 0.191, with AttractMode 2.3 on Ubuntu 16.04.3.  Other versions of the software will be pretty similar, but you may need to modify things here and there.  These steps can also be used as a rough outline on how to get it working for other distros as well, but if youíre using a different distro, then youíll need to adjust any of the commands and steps to fit your specific environment.

I will try to periodically update these instructions, but donít expect them to be updated every single time there is an Ubuntu, MAME or AttractMode release.  Iíll probably update them when I decide to do an update on my own MAME machine, or when I decide to roll another one.

Installing Ubuntu
Iím not going to cover every possible screen and option during the Ubuntu install, but Iíll touch on anything that I think might potentially be confusing, or important to choose specific options.  Anyone with any Linux experience should be able to rush through the install with ease, and for anyone new to Linux, I think this will make for a fairly good foray into Linux, and introduce you to a lot of the basic concepts of Debian based distros.

I really, really recommend going with an LTS server version, not a desktop version.  The desktop version may be very tempting because it has a graphical desktop, but the desktop versions of most linux distros have a lot of extra applications installed that just slow down the computer and take up space, and most of the time it can be really difficult to effectively turn off things like auto-updating.  Installing a server version with no desktop environment will allow you to make a lean, mean mame machine that can be left pretty static once you have everything setup.  Ideally, youíre going to get everything setup and not really worry about updating mame or the frontend unless thereís a new feature you want to take advantage of.

1.) Get a copy of Ubuntu Server 16.4.3 LTS, put it on some form of installable media, and boot the computer you wish to use for your MAME machine.

2.) Select Install Ubuntu Server from the menu.

3.) Pick the appropriate localization options.  I recommend manually picking your keyboard layout as Iíve found Ubuntu sometimes has issues auto-detecting

4.) enter a computer name, username and password when prompted.  Donít bother encrypting your home directory, this isnít exactly a high security situation.

5.) OK, weíre at the first point where we should pay at least a little attention, partitioning the disks.
   Iím going to assume the only OS being installed on this computer is Ubuntu, and that you can use the whole disk.  If youíre doing something else, thatís beyond the scope of these instructions.
   The default should be ďGuided - use entire disk and set up LVMĒ.  This is generally the best option to use, but I have run into a computer where for some reason it just would not work if you used LVM.  LVM is nice to use in certain situations, so certainly not 100% necessary.  I would go with the default unless you have a specific reason not to do so.
   At the time of this writing, I believe the full MAME rom set, with CHDs was somewhere north of 500GB, so using a 1TB drive is probably a good idea.  If you plan to have your roms on a separate disk, thatís fine, but Iíll recommend going with at least a 40GB hard drive, to ensure you have enough space for updates, logs, etc.
   Be sure to read the screens as you go through this section.  Most of them are fine to pick the defaults, but there are two points where it asks you to confirm you really want to proceed, be sure to select yes, as no is the default selection.

6.) For the HTTP proxy, this is generally fine to leave blank unless you need to use a proxy for some reason.

7.) When it asks if you want automatic updates, select ďNo automatic updatesĒ.  We want this system to be as static as possible, automatically installing updates is most likely to cause problems in the future, which we donít want.  We want this whole thing to be ďset it and forget itĒ.

8.) For software selection, I recommend installing the OpenSSH server, and leaving the rest at their defaults (the only other one that should be selected is ďstandard system utilitiesĒ.  You can always install the OpenSSH server later if you skip it here, but it gets everything configured for you if you do it at this point.  If you install it later, youíll need to configure OpenSSH yourself.

9.) You want to choose ďYesĒ when asked about installing GRUB on the master boot record.

10.) Congrats!  Youíve just finished installing Ubuntu.  Look at you go!

11.) Just one final step before we finish this section.  Letís update our OS to make sure weíre as shiny and new as possible:
Code: [Select]
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo reboot now

Getting sound and video working, along with setting up our compilers
   Weíve got some packages that will need to be installed before we can start installing MAME and AttractMode. 
   I recommend doing the remaining tasks over SSH if you can, I just find it more convenient, but it isnít 100% necessary.
   I really, really recommend using screen for the remaining tasks as well, even if youíre not using ssh.  It gives you a persistent session that can run commands even after you walk away from the computer, and certain steps, such as compiling, will take hours.
Code: [Select]
$ screen
1.)   First, letís get sound working
Code: [Select]
$ sudo apt-get install alsa-utils   in the next line, replace <username> with the username you setup when you installed Ubuntu.
Code: [Select]
$ sudo usermod -a -G audio <username>
   By default, your volume will be set at 0, letís turn it up
Code: [Select]
$ sudo alsamixer
   Go through all the audio volume options and turn up anything that needs to be turned up.  I actually went with about 50 for the master volume, otherwise I got distortion on the playback, but you can always come back to this and adjust the volumes later.

2.)   Letís get video working
Code: [Select]
$ sudo usermod -a -G video <username>
$ sudo apt-get install xserver-xorg xinit

   Boo, this is stupid, but there appears to be a bug in the current release of Xorg.  Apparently we can fix it by using Open Box as a window manager.  I will absolutely replace this if I find a better workaround, as this one is annoying.
Code: [Select]
$ sudo apt-get install openbox
$ mkdir ~/.config/openbox

   Now we want to copy PART of a config file in place.  Run this super ugly command:
Code: [Select]
$ sed '/<keyboard>/,/<\/keyboard>/d' /etc/xdg/openbox/rc.xml > ~/.config/openbox/rc.xml
   Last but not least, we want attractmode to launch automatically when openbox launches.
   You can use any text editor you like, I personally like vim, but a lot of people like nano, or other editors.
Code: [Select]
$ vim ~/.config/openbox/autostart
   Add a single line:
Code: [Select]
attract &
   Letís just make sure weíre back in our home directory before we move forward
Code: [Select]
$ cd
3.)   Now, letís get all the tools needed to compile MAME
Code: [Select]
$ sudo apt-get install unzip build-essential libsdl2-dev libfontconfig1-dev qt5-default libsdl2-ttf-dev
Compiling MAME
1.) Download the mame source .zip:
Code: [Select]
$ wget [url][/url]   NOTE: this command will specifically download MAME v.0.191, be sure to change this command to match the version you want to actually download.  You can find the versions at

2.) Next, extract the .zip files we just downloaded
   NOTE: again, modify the commands to match the version of mame youíre compiling
Code: [Select]
$ unzip
$ unzip -d mame
$ cd mame

3.) Letís get rid of the nag screens.  I like to get rid of the nag screens because I feel they detract from the arcade experience, but the nag screens do have important information on them, so you may want to keep them intact.  If you want to keep the nag screens, skip this step.
   NOTE: again, modify the commands to match the version of mame youíre compiling
Code: [Select]
$ cd src/
$ wget
$ patch -p1 -E < suppression_0191u0.txt
$ cd ../

4.) Now to compile MAME
   NOTE: If you arenít yet running a screen session for this, I really recommend doing so, as the compile time is really long, and you may need to walk away from the computer for a while, or if youíre doing this over SSH, the SSH session may be interrupted. 
   To start a screen session, the command is just
Code: [Select]
$ screen   to see the current screen sessions, you can run
Code: [Select]
$ screen -ls   to reconnect to a screen session, run
Code: [Select]
$ screen -r <session ID>
   on to the compiling
Code: [Select]
$ make   now go take a break for a while, compiling will take quite some time.

   Hopefully it compiles fine, if not read the error message and use that to figure out what went wrong, usually you need an additional package you donít yet have installed.

5.) Time to move our mame (or mame64) binary into the correct location.
Code: [Select]
$ sudo mv mame64 /usr/games/   if youíre running running an x86 system, it will be called mame instead of mame64, so alter the command as needed

   Letís go back to our home directory
Code: [Select]
$ cd
   if it doesnít exist, make out mame config folder
Code: [Select]
$ mkdir .mame
$ cd .mame
   And, letís create our mame.ini
Code: [Select]
$ mame64 -cc
6.) Letís modify some of the mame.ini options to make mame run the way we want.
   Iím not going to go into how to use a command line text editor in ubuntu, so for that, youíre on your own.  I prefer vim, but a lot of people like nano.
Code: [Select]
$ vim mame.ini
   First, letís make sure our paths are correct.  You donít need to use the specific paths I used, but here is how I have mine setup.
Code: [Select]
homepath                  $HOME
rompath                   $HOME/mame/roms
hashpath                  $HOME/.mame/hash
samplepath                $HOME/mame/samples
artpath                   $HOME/mame/artwork
ctrlrpath                 $HOME/mame/ctrlr
inipath                   $HOME/.mame;.;ini
fontpath                  .
cheatpath                 $HOME/mame/cheat
crosshairpath             $HOME/mame/crosshair
pluginspath               $HOME/mame/plugins
languagepath              $HOME/mame/language
swpath                    $HOME/mame/software

cfg_directory             $HOME/.mame/cfg
nvram_directory           $HOME/.mame/nvram
input_directory           $HOME/.mame/inp
state_directory           $HOME/.mame/sta
snapshot_directory        $HOME/.mame/snap
diff_directory            $HOME/.mame/diff
comment_directory         $HOME/.mame/comments

hiscore_directory         $HOME/.mame/hi
   Next, letís enable hiscore support.  This allows us to save the high scores in games that donít normally support that.  Go down to the CORE MISC OPTIONS section and change the following values (you may not need to change them all, some may already be set correctly.
Code: [Select]
autoboot_delay            0
plugins                   1
plugin                    hiscore

   Last, assuming weíve compiled with the nonag patch, letís disable the game info screen.  Add these lines to the mame.ini file:
Code: [Select]
skip_gameinfo             1

7.) last but not least
   Put your roms in the ~/mame/roms folder

Installing AttractMode
   Now that weíve got MAME running, letís slap a frontend on it.
1.)   We need a few more things to be able to properly compile attractmode
Code: [Select]
$ sudo apt-get install libopenal-dev libsfml-dev libavutil-dev libavcodec-dev libavformat-dev libavfilter-dev libswscale-dev libavresample-dev libjpeg-dev
2.)   Download the attractmode source
Code: [Select]
$ wget [url][/url]
3.)    Expand it
Code: [Select]
$ tar -zxvf v2.3.0.tar.gz
4.) Letís go ahead and compile the code
Code: [Select]
$ cd attract-2.3.0/
$ make
$ sudo make install

5.) You shouldnít need the attract source files anymore
Code: [Select]
$ cd ..
$ rm -rf attract-2.3.0/
$ rm v2.3.0.tar.gz

Final steps!
   Weíre in the home stretch now

1.)   Letís make it so Ubuntu automatically logs in as our user on boot
Code: [Select]
$ sudo systemctl edit getty@tty1
   We want to enter three lines of text here (be sure to replace <USERNAME> with your username):
Code: [Select]
ExecStart=-/sbin/agetty -a <USERNAME> --noclear %I $TERM

2.)   Letís launch AttractMode for the first time.
Code: [Select]
$ startx
3.)   At this point, youíll want to configure AttractMode, you should be able to follow the documentation on their website in order to get it all configured for use.

   The only one piece I will add to configuring AttractMode is under General > Exit Command, enter ďkillall openboxĒ to make sure you can exit back to a command line when you quit out of attract mode.

4.)   and last, but not least, letís make it so we launch X on login.  This will essentially allow us to turn on the computer, have it automatically login and start our AttractMode frontend, so no user interaction is required to get into AttractMode after pushing the power button.
   One word on editing this last file, I would wait until youíre 100% certain youíre done with making changes to the system.
   I also set a static IP on my MAME machine so I can SSH in whenever I need to make changes.  This is done in /etc/network/interfaces

   Edit the .profile file in your home directory
Code: [Select]
$ vim .profile   and add the following lines:
Code: [Select]
if [ -z "$DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then
exec startx

Iím not SUPER happy with the way this works in 16.04, in 14.04 Iím able to get this working a little smoother so you can exit attractmode and have it exit to a command prompt, but that isnít working in 16.04.  Iím also not happy about having to use OpenBox, but it is what it is for now.  If/when I figure out a way to make it work a little nicer in 16.04, Iíll update this documentation to reflect that.

Let me know if you run into any typos or mistakes with these instructions.  If you see something that could be done in a better way than I outlined, let me know about that too, Iím certainly not perfect, and am always happy to learn.

If you have any questions about any of this, ask away, and good luck!
« Last Edit: December 27, 2017, 01:58:14 pm by loupg »


  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 1
  • Last login:November 09, 2018, 10:24:47 pm
  • I want to build my own arcade controls!
Re: Guide to getting MAME up and running in linux
« Reply #1 on: November 06, 2018, 05:07:29 pm »
Thank you. Your guide was very helpful and the best out there.  The information you provided is a gold mine and not easy to come by.


  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 147
  • Last login:January 19, 2020, 09:55:21 am
    • RGBcommander
Re: Guide to getting MAME up and running in linux
« Reply #2 on: November 09, 2018, 12:33:45 pm »
   on to the compiling
Code: [Select]
$ make   now go take a break for a while, compiling will take quite some time.

Thank you for the good write-up. I just wanted to add that you can significantly speed up compilation time by doing make -j$(nproc) in the multi-core age.
The dependencies are git build-essential libsdl2-dev libsdl2-ttf-dev libfontconfig-dev qt5-default


  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 1
  • Last login:February 28, 2020, 05:51:54 pm
  • I want to build my own arcade controls!
Re: Guide to getting MAME up and running in linux
« Reply #3 on: February 27, 2020, 01:03:32 am »
Awesome guide...

I purchased a 1500-in-1 cocktail cabinet a few months back, its basically just a PC with JAMMA joysticks plugged into. It came pre loaded with a really crappy win2k install. Being a linux guy I had to idea to install Linux on the box. Came across your post, followed it for the most part, instead I used a Ubuntu 18 i386 ISO. I had to upgrade the kernel, because the 4.4 had issues with USB keyboards... fun times. Anyways long story short, I configured it all up, got the Attractmode and MAME working together, however when I launch Donkey Kong (only game i've test thus far) it seems to be running at about a quarter speed and the audio is lagging. Searching around for stuff I maybe need to configure etc, thought I would use this thread as first cab off the rank incase anyone had some tips!

I did a bit of a write up about how I went about things if anyone is interested: