Garry's Mod on CentOS 7
Updated by Linode Contributed by Julian Meyer
Dedicated CPU instances are available!Linode's Dedicated CPU instances are ideal for CPU-intensive workloads like those discussed in this guide. To learn more about Dedicated CPU, read our blog post. To upgrade an existing Linode to a Dedicated CPU instance, review the Resizing a Linode guide.
Garry’s Mod enables complete control and modification of the video game engine, Source Engine. With Garry’s Mod, you can create almost any game you want. Setting up a Garry’s Mod server is a great way to play with friends over the internet while maintaining control over the server.
This guide shows how to create, maintain, and secure a Garry’s Mod server.
Before You Begin
You will need a Steam account and a copy of Garry’s Mod.
Complete our guide: Install SteamCMD for a Steam Game Server. This will get SteamCMD installed and running on your Linode and this guide will pick up where the SteamCMD page leaves off.
NoteThis guide is written for a non-root user. Commands that require elevated privileges are prefixed withsudo
. If you’re not familiar with thesudo
command, you can check our Users and Groups guide.
Prerequisites for Garry’s Mod
From the SteamCMD guide, two additional steps are needed specifically for Gmod.
Add a firewall rule. This command assumes that you have only the firewalld rules in place from the SteamCMD guide. This inserts a rule for port 10999 after the pre-existing rules for SteamCMD.
sudo firewall-cmd --zone=public --add-port=27000 27030/udp --permanent
Install an additional 32-bit package:
sudo yum install ncurses-libs.i686
Install Garry’s Mod
Be sure you are in the directory
~/Steam
, then access theSteam>
prompt.cd ~/Steam && ./steamcmd.sh
From the SteamCMD prompt, login anonymously:
login anonymous
Or log in with your Steam username:
login example_user
Install Gmod to the
Steam
user’s home directory:force_install_dir ./gmod app_update 4020 validate
This can take some time. If the download looks as if it has frozen, be patient. Once the download is complete, you should see this output:
Success! App '4020' fully installed. Steam>
Quit SteamCMD:
quit
Note
To update Gmod, run the above 4 commands again.
Configure Garry’s Mod
This section configures different aspects of the server, including gamemode and workshop addons.
Startup Script
Create a startup script for Gmod with the following contents:
- ~/startgmod.sh
-
1 2 3 4
#!/bin/sh cd ./Steam/gmod screen -S "Garry's Mod Server" ./srcds_run -game garrysmod +maxplayers 20 +map gm_flatgrass
When run, the script will change directories to
~/Steam/gmod
and execute Garry’s Mod in a Screen session. Thesrcds_run
binary can take many more arguments which you can see at Valve’s Developer wiki.Make the script executable:
chmod +x ~/startgmod.sh
Update Script
The Garry’s Mod wiki has instructions to use a script to update Gmod rather than manually through SteamCMD. See under Installing Garry’s Mod.
Automatic Startup After Server Reboots
This will automatically restart Garry’s Mod when your server reboots.
Open Crontab (this will open in
vim
):crontab -e
Enter the startup command. Be sure that the binary flags are the same as in your startup script.
@reboot /home/steam/Steam/gmod/srcds_run -game garrysmod +maxplayers 20 +map gm_flatgrass
To exit
vim
, press Esc, then type :x and hit Enter.
Server Config File
The default server.cfg
file is blank, and any configuration options you want to specify for the server must be added. This is optional, but below is a sane starting point.
- ~/Steam/gmod/garrysmod/cfg/server.cfg
-
1 2 3 4 5 6 7 8
hostname "server_hostname" sv_password "server_password" sv_timeout 60 rcon_password "rcon_password" mp_autoteambalance 1 mp_limitteams 1 writeid writeip
Workshop Addons
Create a collection of addons you want to install on your server at Garry’s Mod Collections. You will need to be logged in to Steam.
Note the collection ID. It is located at the end of the url, denoted by the ‘X’s here:
http://steamcommunity.com/sharedfiles/filedetails/?id=XXXXXXXXX
Acquire a Steam API key from the Steam API Keys page. Note the key.
Paste the Steam API key and Workshop Collection ID into your startup script. For example:
./srcds_run +maxplayers 20 +gamemode terrortown +map cs_office -authkey YOURKEYGOESHERE +host_workshop_collection 157384458
This sets the game for the Trouble in Terrorist Town (TTT) gamemode, but can be changed to your desired gamemode, if you have it downloaded.
For more info on Workshop Addons, see Workshop for Dedicated Servers in the Garry’s Mod wiki.
Using the Server
Now that your server is installed and configured, it can be launched by running the
startgmod.sh
script from yoursteam
user’s home directory.cd ~/ && ./startgmod.sh
Caution
From this point, do not press the Control+C keys while in the console unless you want to stop Gmod.To detach from the screen session running the server console, press these two key combinations in succession:
Control+A Control+D
To bring the console back, type the following command:
screen -r
To stop the server, bring back the Gmod console and press CONTROL + C.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
Join our Community
Find answers, ask questions, and help others.
This guide is published under a CC BY-ND 4.0 license.