September 25, 2024

Terraria (2011)

The platformer I wish I had as a kid.

Terraria (2011)

Screenshot from when I used to play this on Mac, a long, long, time ago.

WARNING! These install instructions require a high degree of nerdery, involving Terminal commands, shell scripts, TMUX sessions, and more.

Intro

There has always been something special about Terraria. It has a vibe that’s easy to relax to. That rain soundtrack hits the spot.

For the game being as old as it is, it’s changed quite a bit. The version I like to play is 1.3.5.3 (released 2017).

(Felt like the defeat of the Moon Lord should have been the end of the game.)

This older version of the game is Linux native and is much less resource intensive on my machine than the newer 1.4 versions.

Terraria is a family favorite w/ my kids. It’s loads of fun to start a playthru on a dedicated server and roll thru the game together.

I’ll show you how I do it at my house.

Install

You’re looking for the Linux installer for 1.3.5.3, which can be hard to find, but if you know where to look you can find it.

The install file is a shell script, which you can run from Terminal:

$ cd /path/to/installer/
$ sh installer.sh

Once you run this, a visual installer UI will open up and guide you thru the process.

32-bit OpenGL Libraries

Here some knowledge I had to learn – your 64-bit operating system w/ it’s 64-bit video drivers won’t work on a 32-bit game.

Terraria is a 32-bit game, and if you try to run it, it won’t work bc you don’t have OpenGL drivers. You might be confused like me, and spend hours trying to figure out why the game is crashing due to lack of OpenGL 2.1 support when you have a system w/ OpenGL 4.4 on it. It’s bc you have 64-bit libraries only.

So what you do is just install the 32-bit OpenGL libraries and problem solved:

$ sudo apt install libgl1:i386 libglu1-mesa:i386

I’m going to put this error in here so the poor sap searching Google can find it:

Microsoft.Xna.Framework.Graphics.NoSuitableGraphicsDeviceException: OpenGL 2.1 support is required!

Amending The Start Script

Once installed, you’re going to have a start.sh file in the game directory. This is the file that you’ll be using to launch the game.

Before you do that, you’ll need to make a few changes to the script so you can control how the game runs on your machine.

Open it up in a text editor and make these changes:

// must put at the top (or game won't launch)
export TERM=xterm

// if you have NVIDIA card, add these to the top too
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only

// if you have Gamemode
// find './"Terraria"' and change to 'gamemoderun ./"Terraria"'

You can run the game in Terminal with:

$ sh start.sh

Add this to ~/.bashrc as an alias:

alias terraria="cd /path/to/terraria && sh start.sh"

Reset Terminal so it reloads the config:

$ source ~/.bashrc

Run it easily from any directory:

$ terraria

Fixing The Keyboard

There is a problem on Linux machines where your character won’t move properly, he will stutter and act weird on ropes.

The problem has to do w/ how Linux handles repeating keys on the keyboard, but you can disable key repeat on the OS using Terminal.

What makes this problem a little tricky is even if you turn off key repeat once, it will spontaneously turn back on a few minutes later.

So I ended up writing a shell script that disables key repeat every 15 seconds. When I kill the script, it reverts back to normal settings:

#!/bin/bash

trap 'xset r rate 500 30; exit' SIGINT

while true; do
    xset r off
    sleep 15
done

You can save this as nokeyrepeat.sh and run it in Terminal with:

$ sh nokeyrepeat.sh

Add this to ~/.bashrc as an alias:

alias nokeyrepeat="sh /path/to/nokeyrepeat.sh"

Reset Terminal so it reloads the config:

$ source ~/.bashrc

Run it easily from any directory:

$ nokeyrepeat

Pressing CONTROL-C will kill the script.

Running A Dedicated Server

These instructions for running a dedicated server on Linux require some advanced stuff, but if you made it this far you might be up for it.

If, by chance, you have a home server (as I do!) you will need to transfer the game files from your local machine over to the remote machine.

You don’t have to install the game using the installer, especially since your remote server probably doesn’t have a screen or user interface.

I used SCP to transfer the files:

$ scp -r /path/to/terraria user@serverip:/path/to/terraria

Once the game files are on the server, you connect to that server using SSH:

$ ssh user@serverip

Then you create a config file for the Terraria server to use:

world=/path/to/your/world.wld
autocreate=0
port=7777
maxplayers=8
password=
motd=Welcome to the server!

You can use a world that you have on your local machine by moving it over to the server. I’ve done it several times.

To start the Terraria server w/ your config file, you’d do this:

$ cd /path/to/terraria/game
$ ./TerrariaServer.bin.x86_64 -config /path/to/serverconfig.txt

But as you can see, the server runs in your Terminal session, and you’re not going to leave that Terminal session open forever. Closing the remote SSH connection would kill your dedicated server.

So, you can use an app called TMUX to run the Terminal session in the background:

$ sudo apt install tmux

I wrote this shell script to automatically provision the TMUX session and run the server in the background:

#!/usr/bin/env bash

config="/path/to/serverconfig.txt"
session="myterrariaserver"

# Kill existing session if it exists
tmux kill-session -t "$session" 2>/dev/null

# Create a new session
tmux new-session -d -s "$session"

# Send commands to the session
tmux send-keys -t "$session" "cd /path/to/terraria/game && ./TerrariaServer.bin.x86_64 -config $config" C-m

So you could save this script as runserver.sh and fire the whole thing off:

$ sh runserver.sh

If you rerun the script it will kill off the currently running server and renew it.

To kill off all currently running sessions:

$ tmux kill-server

Dedicated servers save the world file every 5 minutes, I think.

I didn’t even discuss firewall settings on your server – that’s a whole different article!

Conclusion

To the rare person who read this far, congratulations.

I’m trying to put up all my how-to instructions just in case it’s helpful to others – tho I know it’s helpful to me when I revisit these issues.

Enjoy a great game!

Notes

  • Your character files and world files are stored in ~/.local/share/Terraria.
  • I change my resolution to 1080p prior to loading this game. It fixes some alt-tab issues on my 4k display.
  • I never have been able to get this game to work in Bottles, but Linux native version is best anyway.