0

I've reviewed the different levels of Linux variables and I know I want to add, and possibly update and remove variables to the /etc/environment file.

Looking at other pages, it seems like people are adding variables using the following method to add variables:

echo "export FOO=bar" >> /etc/environment

I mean, it works, and I guess I can use sed to update and remove, but it seems sloppy. Is there a better way to add, update, and remove these variables?

GFL
  • 115

1 Answers1

1

Like the overwhelming majority of traditional Unix configuration files, /etc/environment is just a regular text file. You can manipulate it using whatever tools you want.

Of course, that means the administrator might make a mistake when editing the file. So, it would be a very good idea to test any changes by opening a second terminal session without first closing the session that was used to make the change. If it turns out your change was bad, you can then use the first session to fix it.

The flipside of the configuration file being a regular text file is that you are not limited to some special tools. So, you can:

  • easily make and restore backups of the file you're editing
  • place the file under control of git or some version control system, if you want

You might want to check out etckeeper: a collection of tools to allow placing your entire /etc directory under git or some other version control system, while keeping track of file permissions and other details version control systems might normally ignore. At least in Debian and related distributions, it is available in the standard package collection.

telcoM
  • 96,466