Skip to content

Instantly share code, notes, and snippets.

@bladeSk
Last active April 9, 2024 11:42
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bladeSk/0fd443f9721f222551e0ed2611681c1a to your computer and use it in GitHub Desktop.
Save bladeSk/0fd443f9721f222551e0ed2611681c1a to your computer and use it in GitHub Desktop.
How to install Unity3D on Ubuntu based Linux distros (Kubuntu, Xubuntu, POP_OS, Mint, Neon, Zorin, etc.).

How to install Unity3D on Ubuntu based Linux distros (Kubuntu, Xubuntu, POP_OS, Mint, Neon, Zorin, etc.).

This guide details how to install UnityHub, Unity, VS Code and how to get full C# support with IntelliSense and debugging.

Tested on Kubuntu 22.04.

Installing Unity Hub

Unity Hub won't run on Ubuntu newer than 20.04 because it depends on an outdated libssl. We need to manually install the package from 20.04:

wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb

Install Unity Hub - this is a shorter version of what the official guide does:

wget -O - https://hub.unity3d.com/linux/keys/public | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/unityhub.gpg
echo "deb https://hub.unity3d.com/linux/repos/deb stable main" | sudo tee /etc/apt/sources.list.d/unityhub.list
sudo apt update
sudo apt install unityhub

Launch Unity Hub, log in, install the desired Unity version and verify that it's working.

ℹ️ Note: Unity Hub is also available as an unofficial Flatpak. If all else fails or you're not on Ubuntu, it may be worth a shot.

Installing VS Code

Install VS Code from the official website using the provided .deb. Snap version may work, but you'll likely have issues with Unity integration.

Installing auto-completion/IntelliSense for C# (OmniSharp)

Prerequisites

A complete and up-to-date Mono with msbuild is required instead of the default one available in Ubuntu, otherwise C# code completion won't work. The repo says it's for Ubuntu 20.04, but it works with 22.04 just fine. Uninstall the built in Mono first, if you have it installed.

wget -O - "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xA6A19B38D3D831EF" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mono-official-stable.gpg
echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update
sudo apt install mono-complete

You'll also need DotNET Core for debugging and using OmniSharp without errors. Seems quite reduntant, but I couldn't get it to work without it.

sudo apt install dotnet6

C# support plugin - OmniSharp

Install C# for Visual Studio Code (powered by OmniSharp) from within the VS Code extensions panel.

Go to settings (Ctrl + ,), search for "Use modern Net" and uncheck - this is required for Unity projects and this will use the Mono we installed. Alternatively you can add "omnisharp.useModernNet": false to settings.json.

Restart VS Code. You'll need to set the correct project for code completion and debugging, but there's an easier way - see the next section.

Unity tweaks

Go to Edit > Preferences > External Tools > External Script Editor and select your VS Code instance. Mine was called "Visual Studio Code Insiders (usr/bin/code)". Double click any .cs file in Unity to open the file in VS and ensure the correct project is loaded.

Optional: To cut down compilation time significantly when entering play mode or changing the code go to Edit > Project Settings > Editor > Enter Play Mode Options, tick the box, you can leave the rest unchecked or customize to your needs.

Debugging

The official VS Code debugger is unmaintained and broken. There's an unofficial Debugger for Unity, which worked for me. Instead of using the outlined setup, which seems to be for an older VS Code, you just need to press Ctrl+Shift+P and run "Unity Attach Debugger". Don't forget to turn on the debug mode in Unity in the lower right corner (the bug icon).

What's not working

  • VSync is ignored in the Game View - I'm using if (Application.isEditor) Application.targetFrameRate = 60; as a workaround
  • popups like color pickers or dropdown lists often don't open under the correct control, but in the top left corner of the editor - a small annoyance, probably only KDE specific?
@lmtapia
Copy link

lmtapia commented May 5, 2023

When installing Unity Hub there is an error with keyring as the key was created wit apt-key, the solution that works from Unity forum is create a keyring, import and export the "old" key:

wget -o- https://hub.unity3d.com/linux/keys/public
file public
gpg --no-default-keyring --keyring ./unity_keyring.gpg --import public
gpg --no-default-keyring --keyring ./unity_keyring.gpg --export > ./unity-archive-keyring.gpg
sudo mv ./unity-archive-keyring.gpg /etc/apt/trusted.gpg.d/
sudo apt update
sudo apt-get install unityhub

@chandujr
Copy link

I'm using Nobara Linux (Fedora) and I had a lot of trouble in getting OmniSharp to work properly. I was getting this error "Cannot find Mono (including MSBuild)". Fedora does not provide a separate package for msbuild like mono-msbuild in Arch. It is required by newer OmniSharp versions and they cannot find the command msbuild. Like discussed in this issue, I had to go back till OmniSharp v1.24.x and make these changes in the Settings json in order to make it behave properly:

"omnisharp.useModernNet": false,
"omnisharp.useGlobalMono": "always"

Of course this is a temporary fix.

@steryo
Copy link

steryo commented Aug 19, 2023

C# extension needed one more tweak for me which is checking the Dotnet > Server : Use Omnisharp parameter. Works perfect in Kubuntu 22.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment