I have experimented with many approaches to setting permanent environment variables EC2 instances running Amazon Linux 2, but none of the approaches are persistent across users and across login sessions.
What specific syntax and process will successfully set environment variables so that the values of the variables will be available to all users and during every session?
So far, methods that I have tried include setting values separately in each of the following three files during the USERDATA's launch script for the instance:
/etc/csh.cshrc
/etc/environment
/etc/profile
I tried each file one at a time and not all three at the same time.
I also tried using Python's os.environ
but that did not work either.
User Suggesions
Per @NasirRiley's suggestion, it now works when I create a setVars.sh
file and place it in /etc/profile.d
during the instance's USERDATA
startup sequence:
#!/bin/bash
export SOME_VAR_NAME=some-var-value
/etc/profile.d
./etc/profile.d
.export SOME_VAR_NAME=some-var-value
. What you have there is just going to print "export SOME_VAR_NAME=some-var-value" in the terminal when the user opens it. Replace theecho
line withexport SOME_VAR_NAME=some-var-value
.