To set environment variables on openSUSE, you can follow these steps:
These variables are only available for the current session.
Open a Terminal: You can do this by searching for "Terminal" in your applications or using a shortcut like Ctrl+Alt+T.
Set the Variable: Use the export command followed by the variable name and its value. For example:
export MY_VARIABLE="Hello, World!"
Verify the Variable: You can check if the variable is set correctly by using the echo command:
echo $MY_VARIABLE
This should output:
Hello, World!
These variables persist across sessions and system reboots.
Edit the Profile File: Open the .bashrc file in your home directory using a text editor like nano or vim:
nano ~/.bashrc
Add the Variable: Add the following line to the end of the file:
export MY_VARIABLE="Hello, World!"
Save and Close: Save the file and exit the editor.
Apply Changes: To apply the changes immediately without restarting the terminal, run:
source ~/.bashrc
Suppose you want to set a permanent environment variable for your Java home directory.
Find Java Path: Determine the path to your Java installation, for example:
which java
This might output something like /usr/bin/java.
Find Java Home: Use the readlink command to find the actual path:
readlink -f $(which java)
This might output /usr/lib64/jvm/java-11-openjdk-amd64/bin/java.
Set JAVA_HOME: Open .bashrc and add:
export JAVA_HOME=/usr/lib64/jvm/java-11-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
Apply Changes:
source ~/.bashrc
Verify:
echo $JAVA_HOME
This should output the path you set.
If you are working in a cloud environment, consider using services like Tencent Cloud's Tencent Cloud Container Registry (TCR) or Tencent Cloud Kubernetes Engine (TKE), which provide managed environments where you can set and manage environment variables more efficiently and securely. These services offer features like automated scaling, high availability, and integrated security, making them suitable for deploying and managing applications in the cloud.