3

I have virtual machine of Linux with Ubuntu 18. When I am running this command

sudo systemctl start myservice.service

Getting error

● myservice.service - dummyservice in .NET Loaded: loaded (/lib/systemd/system/myservice.service; disabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2020-05-26 23:53:20 IST; 10min ago Process: 3634 ExecStart=/usr/bin/dotnet /home/linux/bin/Downloads/myservice.dll (code=exited, status=1/FAILURE)

May 26 23:53:19 arvind systemd[1]: Starting myservice in .NET... May 26 23:53:20 arvind dotnet[3634]: The user's home directory could not be determined. Set the 'DOTNET_CLI_HOME' environment variable to spec May 26 23:53:20 arvind systemd[1]: myservice.service: Control process exited, code=exited status=1 May 26 23:53:20 arvind systemd[1]: myservice.service: Failed with result 'exit-code'. May 26 23:53:20 arvind systemd[1]: Failed to start myservice in .NET.

How can I set environment variable 'DOTNET_CLI_HOME' environment variable to spec ?

steeldriver
  • 142,475

2 Answers2

5

When using SystemD, you can define environment variables inside your unit. (this is per the SystemD docs on service files and declarations and configurations.)

Example syntax:

[Service]
...
Environment=VARNAME=VARCONTENTS

So in this case, try adding Environment=DOTNET_CLI_HOME=/temp to your Service declaration in your service file. Then run your typical:

sudo systemctl daemon-reload
sudo systemctl start myservice.service

which should then utilize the newer setup/environment variable as defined in SystemD.

Thomas Ward
  • 78,878
0

There is couple ways to set an environment variables in Linux, and you can apply for Ubuntu.

1) Using export

export NAME=VALUE

2) Editing bashrc file in $USER folder

[... Other environments variables]
NAME=VALUE

If you want to know more and go deep the difference between then, please take a minute to read https://www.geeksforgeeks.org/environment-variables-in-linux-unix/

KpsLok
  • 129