Compiling / playing nethack 3.6.0 on Ubuntu or Debian

UPDATE: Instructions added for enabling the hilite_status feature to get nice coloured Hitpoint & Hunger highlighting

After a 10+ year hiatus, the NetHack DevTeam is happy to announce the release of NetHack 3.6, a combination of the old and the new.

- nethack 3.6.0 release notes

It took me a while to figure out how to actually get nethack v3.6.0 running on Ubuntu, so I’ve shared what I learned for others.

Thanks to Jochen, we can also get this compiling on Debian Jessie.

Get setup

  • Install the dependencies
    • sudo apt-get install flex bison build-essential libncurses5-dev checkinstall
  • Get the source
  • Extract the source
    • tar xpvzf nethack-360-src.tgz

Prepare the source

  • Edit include/unixconf.h
    • Change /* #define LINUX */ to #define LINUX
  • Edit sys/unix/hints/linux to be as here.
    • For Debian Jessie, change the HACKDIR=... line to be HACKDIR=$(PREFIX)/lib/games/$(GAME)dir
  • If you want to enable Status Hilite’s;
    • Edit include/config.h
    • Change /* #define STATUS_VIA_WINDOWPORT */ to #define STATUS_VIA_WINDOWPORT
    • Change /* #define STATUS_HILITES */ to #define STATUS_HILITES
  • sh ./sys/unix/setup.sh sys/unix/hints/linux (sets up the Makefiles correctly)

Build & install

  • make all
  • sudo checkinstall (will create a package and install it for you)
    • Hit y to create default docs
    • Enter nethack 3.6.0 then hit <Enter> twice when prompted
    • At the options screen, change option 12 to say nethack-common. This avoids accidentally installing any old version from your package manager.
    • Hit <Enter> to continue
    • If you see an error “Some of the files created by the installation are inside the home directory“;
    1. Hit n (it’s just a temporary file), then
    2. Hit y to continue (we do not want those files in our package).

Uninstallation

To uninstall, use your favourite package manager, or sudo dpkg -r nethack.

Play!

Now you can run the game via nethack.

Need some help getting starting with nethack? Read the v3.6.0 guidebook.

Tagged , , , ,

37 thoughts on “Compiling / playing nethack 3.6.0 on Ubuntu or Debian

  1. Matt Winner says:

    I’m getting the following error running lubuntu 14.10:

    ..sys/share/unixtty:c:41:20: fatal error: curses.h: no such file or directory
    #include

    I assumed that I needed libncurses5-dev, but for some reason I have been unable to install this package through the ordinary channels. Any tips?

    • Jess Telford says:

      14.10 has gone past its 9 month support cycle, so all the apt repositories have been moved (why they do this, I have no idea). An indicator is getting lots of 404 errors when doing an `apt-get update`.

      To fix it, run this command: http://askubuntu.com/a/710884/18693

      I’ve had to do it on my old boxes in the past too, works a treat!

      Then you can re-try the installation of libncurses.

      • Matt Winner says:

        Many thanks for putting together this guide. I am massively excited for Nethack 3.6.

        I’m currently getting from apt-get update: “could not resolve ‘us.old-releases.ubuntu.com.'”

        Any ideas? I might very well need to modernize my system, but it might be a day’s worth of work πŸ™‚

        • Jess Telford says:

          Hmm, that’s no good. Looks like you may have had a country-specific source in there.

          Try running this command to use the general “http://old-releases.ubuntu.com/ubuntu” instead of the country-specific “http://us.old-releases.ubuntu.com/ubuntu”:

          sudo sed -i -e ‘s/us.old-releases.ubuntu.com/old-releases.ubuntu.com/g’ /etc/apt/sources.list

          Then follow it up with a:

          sudo apt-get update

          • Matt Winner says:

            Massive compiling success after I had libncurses5-dev, bison, and flex installed from the old-releases.ubuntu.com repository.

            Thanks again! You, my friend, are a damned wizard πŸ™‚

          • Jess Telford says:

            Awesome to hear!

            … But, I like think of myself as more of a Rogue or a Barbarian πŸ˜‰

  2. Matt Winner says:

    Also, it might be useful to remind folks that might need to “sh ./setup.sh hints/linux”

    • Jess Telford says:

      Just doing `./setup.sh` should correctly execute it as a shell script. But it can’t hurt to be explicit in my instructions. I’ve updated it to have `sh ./setup.sh`, thanks!

      • Matt Winner says:

        You shell must be more awesome than mine is. I have to actually type the “sh” command πŸ™‚

        • Jess Telford says:

          It might be that the setup.sh didn’t keep the executable bit set when you extracted the source.

          What’s the output of:

          ls -hAl sys/unix/setup.sh

          Mine is:

          -rwxrwxr-x 1 jess jess 1.1K Jun 12 2015 sys/unix/setup.sh

          • Matt Winner says:

            It says, with sudo:

            “ls: cannot access sys/unix/setup.sh: No such file or directory”

            Typing the “sh” doesn’t waste too many minutes out of my day, so I don’t mind πŸ™‚

  3. Jochen says:

    Thanks for this. To make it work with Debian Jessie I had to change https://gist.github.com/jesstelford/67eceb7a7fa08405f6b7#file-makefile-L14

    to:

    HACKDIR=$(PREFIX)/lib/games/$(GAME)dir

  4. Marcin says:

    Thank you so much!

  5. BeeHynes says:

    Hey, when I use make all I get
    make: *** No rule to make target `all’. Stop.

    Any insight into what the issue may be ? Running Ubuntu 14.04

  6. Beuz says:

    Thank you very much, it worked perfectly. I actually installed linux distro just to play this game. I hate that you can’t go fullscreen on windows console and don’t really like to play the “graphical” version. I was kind of lost, so thank you, again!

  7. IRI says:

    On Ubuntu 14.04 LTS after the installation the command “nethack” tries to launch it from /usr/bin/nethack, but actually game is placed in /usr/games/. I don’t want to spend time to find where to fix it, so I just run it with “/usr/games/nethack”. But probably this info will be helpful for unfamiliar people.

  8. Paul Meyer says:

    Solved issue:

    If you get “Cannot create save file” when trying to save, go to /var/games/nethack, create a save directory, and give it root ownership and full permissions:

    sudo mkdir /var/games/nethack/save
    sudo chmod 777 /var/games/nethack/save

    That worked for me.

  9. RONALD VANIWAARDEN says:

    Followed your instructions on Linux Mint Cinnamon and had to add in a few packages to get all the X11 build finished. However, once built, I cannot run because of problems with the fonts:

    vaniwaar@storage ~/nh/install/games $ ./nethack
    xset: bad font path element (#9), possible causes are:
    Directory does not exist or has wrong permissions
    Directory missing fonts.dir
    Incorrect font server address or syntax
    Warning: cannot write scoreboard file record
    Unable to open SYSCF_FILE.

    I checked and fonts.dir is there in lib/nethackdir and am a bit at a loss of how to resolve this…

  10. Ron says:

    Does it create nethack-x11 with tiles included?

    • Jess Telford says:

      I’m not sure, sorry. I’ve only ever played the TTY version.

      • Paul Hoff says:

        Ubuntu 16.04 – Didn’t make any f your changes to config file but built generated nethack executable ok. Getting error ‘Unable to open SYSCF_FILE’ when trying to run. From linux-x11 hint file …
        HACKDIR=$(PREFIX)/games/lib/$(GAME)dir
        SHELLDIR = $(PREFIX)/games
        INSTDIR=$(HACKDIR)
        VARDIR = $(HACKDIR)

        POSTINSTALL= cp -n sys/unix/sysconf $(INSTDIR)/sysconf; $(CHOWN) $(GAMEUID) $(INSTDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(INSTDIR)/sysconf; chmod $(VARFILEPERM) $(INSTDIR)/sysconf;

        I manually copied sysconf file into dir ‘/usr/games/lib/nethackdir’ but problem persist. Its almost like POSTINSTALL stages are not being done.

        • Paul Hoff says:

          Found out problem after typing ‘make all’ then ‘make install’ fixed it. Game installes to dir
          ~/nh/install/games and yes x11 titles work πŸ™‚

          Script below will get new updates as they are published on website and auto install them for you thanks.

          #!/bin/bash
          #PROGDESC – instnethack – Install the latest version of nethack from source
          #PROGDESC – instnethack – using ‘x11-linux’ hints or config with graphic tiles.

          ########################################################################
          # Ver# Auth Date Desc
          # 1.0 PPH 2017/03/13 Initial install.
          ########################################################################

          #INFO – from websites
          #http://jes.st/2015/compiling-playing-nethack-360-on-ubuntu/

          #
          #VARS
          #

          progver=”1.0″; echo “Running ‘instnethack VER#”$progver” …”

          newver=`wget -q http://www.nethack.org/common/index.html -O – | \
          grep “current” | awk -F\NetHack ‘{ print $2 }’ | \
          awk -F\) ‘{ print $1 }’ | tr -d ‘ ‘`
          echo “newver = “$newver
          snewver=`echo $newver | tr -d ‘.’`
          echo “snewver = “$snewver
          OLOGNAME=$LOGNAME
          dldn=”/home/”$OLOGNAME”/Downloads”
          echo “dldn = “$dldn
          cd $dldn
          fn=”nethack-“$snewver”-src.tgz”
          tfn=”nethack-“$snewver”-src.tar”
          dlfn=$dldn/$fn
          edir=`echo $dldn”/nethack-“$newver”/src”`
          echo “edir = “$edir

          #
          #MAIN
          #

          ls -la $dlfn
          if [ ! -f $dlfn ]; then
          echo “DL’ing file ‘”$tfn”‘ …”
          #https://downloads.sourceforge.net/project/nethack/nethack/3.6.0/nethack-360-src.tgz?
          #r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fnethack%2F%3Fsource%3Dtyp_redirect&ts=1489425575&use_mirror=nchc
          wget -O – http://prdownloads.sourceforge.net/nethack/nethack-$snewver-src.tgz?download 2> $dldn/WGETO >/dev/null
          echo; dlurl=`cat $dldn/WGETO | grep “\-\-” | tail -1 | awk -F\ ‘{ print $NF }’`; echo
          echo “dlurl = “$dlurl
          wget -N $dlurl
          ls -la $dlfn
          fi

          if [ -f $fn ] && [ ! -f $tfn ]; then
          gzip -dc $fn > nethack-$snewver-src.tar
          tar xf nethack-$snewver-src.tar
          fi

          #TEST – Delete exe to force rebuilding …
          #rm $edir/nethack
          #TEST – END

          if [ ! -f $edir/nethack ]; then
          #Inst prereqs
          echo “Installing prereqs …”
          # x11 tiles
          sudo apt-get install libxt-dev libxaw7-dev libx11-dev byacc flex xfonts-utils
          # below needed only for cli not tile or x11 install of game?
          # sudo apt-get install flex bison build-essential libncurses5-dev
          cd nethack-$newver/sys/unix
          echo “Running setup.sh …”
          ls -la setup.sh
          ls -la hints/linux-x11
          sh setup.sh hints/linux-x11
          cd ../..
          make all
          # if build fails remove all files
          if [ “$?” != “0” ]; then
          echo “ERROR – Build failed removing files …”
          cd nethack-$newver
          make spotless
          exit 1
          else
          # May or may not need to be done after build per docs
          cd $dldn/nethack-$snewver
          make install
          echo “INFO – Build sucessfull !”
          fi
          else
          echo “INFO – Nethack is already compiled and built …”
          fi

          cd /home/$OLOGNAME/nh/install/games
          ls -la nethack
          echo “Running Nethack …”
          ./nethack

          cd

    • paxed says:

      Just use the linux-x11 hints file instead of the plain linux one, and you’ll get that.

  11. Simba Lion says:

    I have the following errors on Debian 8.5:

    Warning: cannot write scoreboard file record

    Hit return to continue:
    Unable to open SYSCF_FILE.

  12. David Lowry says:

    Thanks for the guide. I went through and everything seemed to work without a hitch. However, now I get “bash: nethack: command not found” which leads me to believe it didn’t actually install?

    The only thing that I can think of is that I’m running Ubuntu 14.04 and I followed this “For Debian Jessie, change the HACKDIR=… line to be HACKDIR=$(PREFIX)/lib/games/$(GAME)dir” which I now realize I don’t think I needed to do.

    Any idea why it’s not working? Thanks!

  13. Roger H. says:

    I’m using Bunsenlabs (Debian Jessie) and got the following on the final step when using sudo checkinstall:

    /bin/sh: 2: cannot create /root/nh/install/games/nethack: Directory nonexistent
    Makefile:250: recipe for target ‘dofiles’ failed
    make[1]: *** [dofiles] Error 2
    make[1]: Leaving directory ‘/home/roger/Downloads/nethack-3.6.0’
    Makefile:315: recipe for target ‘install’ failed
    make: *** [install] Error 2

    **** Installation failed. Aborting package creation.

  14. Qionglu735 says:

    Hi
    I am following your guide, and getting this error on ubuntu server 16.04

    make[5]: ‘../include/date.h’ is up to date.
    make[5]: Leaving directory ‘/root/nethack-3.6.0/src’
    make[4]: Leaving directory ‘/root/nethack-3.6.0/util’
    ( cd dat ; ../util/dlb cf nhdat help hh cmdhelp history opthelp wizhelp dungeon tribute asmodeus.lev baalz.lev bigrm-*.lev castle.lev fakewiz?.lev juiblex.lev knox.lev medusa-?.lev minend-?.lev minefill.lev minetn-?.lev oracle.lev orcus.lev sanctum.lev soko?-?.lev tower?.lev valley.lev wizard?.lev astral.lev air.lev earth.lev fire.lev water.lev ???-goal.lev ???-fil?.lev ???-loca.lev ???-strt.lev bogusmon data engrave epitaph oracles options quest.dat rumors )
    make[3]: Leaving directory ‘/root/nethack-3.6.0’
    ( cd dat ; cp nhdat license /usr/games/lib/nethackdir )
    ( cd /usr/games/lib/nethackdir ; nhdat license ; \
    chgrp games nhdat license ; \
    chmod 0644 nhdat license )
    /bin/sh: 1: nhdat: not found
    make[2]: Leaving directory ‘/root/nethack-3.6.0’
    (cd dat ; cp symbols /usr/games/lib/nethackdir )
    cp src/nethack /usr/games/lib/nethackdir
    cp util/recover /usr/games/lib/nethackdir
    if test -n ‘/usr/games’; then rm -f /usr/games/nethack; fi
    if test -n ‘/usr/games’; then \
    sed -e ‘s;/usr/games/lib/nethackdir;/usr/games/lib/nethackdir;’ \
    -e ‘s;HACKDIR/nethack;HACKDIR/nethack;’ \
    /usr/games/nethack ; fi
    ( cd /usr/games/lib/nethackdir ; nethack recover ; \
    chgrp games nethack recover )
    /bin/sh: 1: nethack: Permission denied
    chmod /usr/games/lib/nethackdir/nethack
    chmod: missing operand after β€˜/usr/games/lib/nethackdir/nethack’
    Try ‘chmod –help’ for more information.
    Makefile:269: recipe for target ‘dofiles’ failed
    make[1]: *** [dofiles] Error 1
    make[1]: Leaving directory ‘/root/nethack-3.6.0’
    Makefile:334: recipe for target ‘install’ failed
    make: *** [install] Error 2

    Any help?

  15. paxed says:

    Instead of editing config.h, you could’ve added -DSTATUS_VIA_WINDOWPORT to the hints file.

  16. nms says:

    Thank you so much for this page, it worked like a charm for me! πŸ™‚

    Would you know where I can find a sample .nethackrc for 3.6.0? I’m looking into my /usr/games/lib/nethackdir (actually, I ran a find on my whole system, too) and could not find anything.

    Many thanks in advance,
    Nuno

  17. Jay says:

    I get a command not found when trying to use checkinstall on my Centos7.
    Any ideas on how to correct that?

  18. Kendall says:

    This is an old thread so I’m not expecting a response but if you could help me out, I’m running into an error when running make all. I keep receiving an error in monst.c that “config.h” is not found. I followed your guide and redid everything but it’s just not working. Help? D:

  19. Songping Lee says:

    I compiled and ran it successfully, but the window is full of garbage characters ? Have you encountered this situation ?

    Really appreciate your post and hope your reply.

    • Songping Lee says:

      @Jess Telford I’m sorry to bother you. I recompile it and it works, maybe I change the source code slightly.

      I’m really sorry.

      Have a nice day πŸ˜€

Leave a Reply

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