I'm trying to use dotnet (.NET Core) with cron jobs, but it seems the path variable for dotnet doesn't exist in the scope of cron. I'd like to add the path to cron, but I need to know where dotnet is actually installed to from a typical Ubuntu installation. Also knowing how to add the path variable to cron would be helpful also, but I think I can figure that out once I have the dotnet installation directory.
4 Answers
After seeing the comment by Gomes, I checked and it seems both are valid in my system:
$ /usr/bin/dotnet --version
2.1.400
$ /usr/share/dotnet/dotnet --version
2.1.400
I did a bit more research and it appears that the usual way to find this in many unix dialects (as per https://kb.iu.edu/d/acec) is with the help of whereis
command:
$ whereis dotnet
dotnet: /usr/bin/dotnet /usr/share/dotnet /usr/share/man/man1/dotnet.1.gz
But with further scrutiny, I could see that /usr/bin/dotnet
is just a symlink to /share/dotnet/dotnet
:
/usr/bin$ ll dotnet
lrwxrwxrwx 1 root root 22 Jun 29 17:48 dotnet -> ../share/dotnet/dotnet*
And that page also shows how to see which one the operating system uses when running a command you type in the terminal, which command
:
$ which dotnet
/usr/bin/dotnet

- 324
- 2
- 5
-
3if you are installing using snap (as per microsoft documentation), use `whereis dotnet` to get right installation path. – Jag Mar 15 '21 at 01:38
In my case (I've been installed dotnet with dotnet-install.sh script when it was already installed on my system with snap) the path is ~/.dotnet
. May be it helps someone.

- 107
- 1
- 8
-
3Also it wasn't add that path to PATH environment variable. So I've created symlink with `sudo ln -s ~/.dotnet/dotnet /usr/bin/dotnet` – Makich Mar 29 '22 at 18:38
By default, .NET Core ("dotnet") is installed to /usr/share/dotnet/
As far as I can tell, one cannot permanently set a path environment variable for cron, but can do so temporarily by adding a script to the crontab file before the part that you need the variable for (see here)
Alternatively, you can just specify the absolute path to dotnet in the crontab i.e. /usr/share/dotnet/dotnet run --project /path/to/csproj/

- 2,013
- 3
- 25
- 39
For WSL2 (Linux under Windows), it's a bit different: if you've already got .NET Core installed for Windows, the dotnet-install.sh
script recognises it and doesn't install it again. However, this means that the dotnet
command doesn't work out of the box (i.e., unless you explicitly create an alias for it); instead (for WSL2) you need dotnet.exe
. However, whereis dotnet
will still show you the installation folder (which is in the Windows-managed part of the file-system).

- 4,306
- 3
- 30
- 30