If you are using Ubuntu as one of your tags says, you'll have a directory called
/etc/profile.d
As root, create a file inside. Let's call it
dotnet_optout.sh
Open it with a text editor and enter the following:
#!/bin/sh
DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_CLI_TELEMETRY_OPTOUT
MakeUodate: You don't have to make the file executable by all:. It's just a force of habit from my early Linux days. It doesn't hurt anything if you do, though.
chmod a+x /etc/profile.d/dotnet_optout.sh
Afterwards, you can log out and back in or:
bash
And that will start a new shell session which sources /etc/profile.d/dotnet_optout.sh
To confirm when you're done, enter:
echo $DOTNET_CLI_TELEMETRY_OPTOUT
You'll get an output of 1.
In short, any script that is executable by everyone who is using bash (or some sh-like shell that sources /etc/profile) that you put inside of that directory will affect everyone's environment.
If you have users who use other shells, the configuration will be similar, but you'll need to update different configuration files.