(By Linux I am of course referring to GNU/Linux)
Releasing your game for Linux is super hard, right? Well, if you have a standard MonoGame setup and happen to be using Desktop OpenGL for rendering your graphics, you're in luck.
Assuming you already have your development environment setup for targeting Desktop OpenGL, all it takes are three super easy steps:
As described in the monogame documentation, the command for building a Linux standalone is this:
dotnet publish -c Release -r linux-x64 /p:PublishReadyToRun=false /p:TieredCompilation=false --self-contained
Note that no command in this guide needs administrator or superuser privileges, so you should not execute them as root or administrator.
The command is the same on any operating system. It does of course require you to have the .NET SDK installed, which you already have if you are able to build a release for Windows. If not, the MonoGame documentation has the details.
Running the build from the Linux commandline:
./relative/path/to/YourGame/bin/Release/netcoreapp3.1/linux-x64/publish/YourGame
or:
/full/path/to/YourGame/bin/Release/netcoreapp3.1/linux-x64/publish/YourGame
Your game should start as normal. In case you get an error, see below in the troubleshooting section.
It is recommended to distribute your game as a tar.gz archive as this preserves file permissions.
The CLI command for creating a tar.gz archive is:
tar -czvf [[filename.tar.gz]] directory
So for your game this would look somewhat like this:
tar -czvf YourGameName.tar.gz YourGame/bin/Release/netcoreapp3.1/linux-x64/publish
Source for Linux, tested on Arch Linux.
See also the man page of tar.
- Use 7zip or tar to create a *.tar file out of the folder YourGame\bin\Release\netcoreapp3.1\linux-x64\publish
- Use 7zip or gzip to turn the *.tar into a *.tar.gz file.
Told you - super easy. What, you encountered problems? Let me know!
You can now distribute your YourGame.tar.gz archive as a Linux release in exactly the same way as the .zip for Windows release.
To run your game, your customers can simply run the following two commands:
tar -xzvf YourGameName.tar.gz
./publish/YourGameName
Of course, if you rename the publish folder to the name of your game before archiving it, that changes the latter command into something a bit more presentable.
You may also want to look into enhancing your release with a .desktop file to allow distros to display your game with desktop menu icons etc.
How to create desktop entries blog post
You may run into the following error when trying to run your Linux build:
Process terminated. Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.
[...]
The easy fix is adding the following property to your YourGameName.csproj file, before building your game again.
<PropertyGroup>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
Source for this fix, that I tested on Arch Linux.