Skip to main content
deleted 121 characters in body
Source Link
CodeMed
  • 5.4k
  • 50
  • 112
  • 153

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 even createdcreate a setVars.sh file and placed the fileplace it in /etc/profile.d during the instance's USERDATA startup sequence:

#!/bin/bash echo 'exportexport SOME_VAR_NAME=some-var-value'value 

But only a blank line results when I log in separately and type echo $SOME_VAR_NAME in a new terminal window.

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, I even created a setVars.sh file and placed the file in /etc/profile.d during the instance's USERDATA startup sequence:

#!/bin/bash echo 'export SOME_VAR_NAME=some-var-value' 

But only a blank line results when I log in separately and type echo $SOME_VAR_NAME in a new terminal window.

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 
added 392 characters in body
Source Link
CodeMed
  • 5.4k
  • 50
  • 112
  • 153

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, I even created a setVars.sh file and placed the file in /etc/profile.d during the instance's USERDATA startup sequence:

#!/bin/bash echo 'export SOME_VAR_NAME=some-var-value' 

But only a blank line results when I log in separately and type echo $SOME_VAR_NAME in a new terminal window.

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.

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, I even created a setVars.sh file and placed the file in /etc/profile.d during the instance's USERDATA startup sequence:

#!/bin/bash echo 'export SOME_VAR_NAME=some-var-value' 

But only a blank line results when I log in separately and type echo $SOME_VAR_NAME in a new terminal window.

Source Link
CodeMed
  • 5.4k
  • 50
  • 112
  • 153

How to set environment variables permanently in Amazon Linux 2

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.