Table of Contents Introduction What are Environment Variables? Purpose of Environment Variables Types of Environment Variables Setting Environment Variables for Single Users 5.1 Temporary Environment Variables 5.2 Permanent Environment Variables for Single Users Setting Environment Variables for All Users 6.1 Permanent Environment Variables (Using Profile File) 6.2 Permanent Environment Variables (Using Environment File) Verifying the Environment Variable Troubleshooting 8.1 Troubleshooting in Firefox 8.2 Troubleshooting in Chrome Conclusion Introduction In the operating system, environment variables are essential components that enable users to store and access information across various processes and user sessions. They provide a useful way to customize system behavior, configure applications, and simplify repetitive tasks. This guide will explore multiple approaches to setting environment variables in Linux, catering to both individual users and system-wide configurations. Linux What are Environment Variables? Environment variables are values that can change and impact how programs behave on a computer system. They are name-value pairs that all processes can access within a particular user environment or shell session. These variables provide a flexible and convenient method for managing system-wide settings, configuring applications, and customizing system behavior. Purpose of Environment Variables: Environment variables serve several crucial purposes: Customization: Environment variables allow users to tailor their computing experience by defining specific settings or preferences. For instance, a user can set an environment variable to specify their preferred text editor or default directory. Application Configuration: Applications often rely on environment variables to access configuration settings or locate resources. For example, the PATH environment variable informs applications where to search for executable files. System-Wide Management: Administrators can use environment variables to manage system-wide settings and configurations. For instance, setting the TZ environment variable defines the default time zone for all users. Types of Environment Variables: Environment variables can be classified into two main categories: These variables are specific to a user and are stored in their profile files. Changes to user environment variables only affect the environment of the respective user. User Environment Variables: These variables are global to the system and are defined in system-wide configuration files. Changes to system environment variables affect the environment of all users. System Environment Variables: SSLKEYLOGFILE=/home/stanley/Documents/Coding/browser-log/sslkeylog.log Setting Environment Variables for Single Users Method 1: Temporary Environment Variables Temporary environment variables are defined within the current shell session and cease to exist once the shell terminates. To set a temporary environment variable, use the following syntax: SSLKEYLOGFILE=/home/stanley/Documents/Coding/browser-log/sslkeylog.log Method 2: Permanent Environment Variables for Single Users Permanent environment variables persist across shell sessions and are available to the user who sets them. To set a permanent environment variable for a single user, use the command followed by the variable definition: export export SSLKEYLOGFILE=/home/stanley/Documents/Coding/browser-log/sslkeylog.log To make this permanent change effective, add the command and variable definition to the user's initialization file. These files are typically located in the user's home directory: export : For bash users ~/.bashrc : For zsh users ~/.zshrc Open the appropriate file using a text editor like or . Add the command followed by the variable definition to the end of the file. Save the file and exit the text editor. The next time the user logs in or opens a new terminal session, the permanent environment variable will be set. nano vi export Setting Environment Variables for All Users Method 1: Permanent Environment Variables for All Users (Using Profile File) Permanent environment variables for all users can be set by adding them to the file. This file is read by all users when they log in, so any changes made to the file will be reflected in the environment of all users. /etc/profile Open the file in a text editor with : /etc/profile sudo sudo nano /etc/profile Add the following line to the end of the file: export SSLKEYLOGFILE=/home/stanley/Documents/Coding/browser-log/sslkeylog.log Save the file and exit the text editor. All users who log in after you make this change will have the environment variable set to . SSLKEYLOGFILE /home/stanley/Documents/Coding/browser-log/sslkeylog.log Method 2: Permanent Environment Variables for All Users (Using Environment File) Permanent environment variables for all users can alternatively be set by adding them to the file. This file is also read by all users when they log in, so any changes made to the file will be reflected in the environment of all users. /etc/environment Open the file in a text editor with : /etc/environment sudo sudo nano /etc/environment Add the following line to the end of the file: export SSLKEYLOGFILE=/home/stanley/Documents/Coding/browser-log/sslkeylog.log Save the file and exit the text editor. All users who log in after you make this change will have the environment variable set to . SSLKEYLOGFILE /home/stanley/Documents/Coding/browser-log/sslkeylog.log Verifying the Environment Variable To verify that the environment variable has been set correctly, use the command followed by the variable name: echo echo $SSLKEYLOGFILE This command should display the specified path: /home/stanley/Documents/Coding/browser-log/sslkeylog.log This confirms that the environment variable has been set effectively. Here are the logged keys below Please note that Chrome should work with this setup out of the box but if it does not work, here are the steps to troubleshoot it. Troubleshooting Step 1: Open Firefox Launch the Firefox browser on your computer. This will open the main Firefox window, ready for further configuration. Step 2: Enter Configuration Settings Type into the Firefox address bar and press Enter. This will take you to the advanced configuration settings, where you can modify various aspects of Firefox's behavior. about:config More Resource Step 3: Proceed with Caution Firefox will display a warning message stating that you are about to enter the configuration settings. Click on "Accept the Risk and Continue." Be cautious while making changes in these settings, as it may affect browser behavior. Step 4: Search for Security.fileuri.strict_origin_policy In the search bar at the top of the page, type . This setting determines whether Firefox enforces the same-origin policy for file:// URLs. security.fileuri.strict_origin_policy More Resource Step 5: Toggle the Value Double-click on the entry to toggle its value. Set it to to disable the strict origin policy for local files. security.fileuri.strict_origin_policy false Step 6: Confirm Changes After changing the value, close the about:config tab. Your changes are now saved. Step 7: Restart Firefox To apply the changes, restart Firefox. Close the browser and open it again. This will ensure that the new settings are in effect. Chrome Google Chrome also allows you to specify a log file when launching the browser. Here's how you can do it: Open the Command Prompt or Terminal: On Linux, open the Terminal using your preferred method. Use the command to navigate to the directory where Google Chrome is installed. This might vary based on your operating system. Navigate to the Google Chrome Installation Directory: cd cd path\\to\\chrome Use the following command to launch Chrome with logging enabled. Replace with the desired path and filename for your log file. Launch Chrome with Logging: /path/to/logfile.log chrome --enable-logging --v=1 --log-file=/path/to/logfile.log After launching with the specified log file, check the log file for relevant information. You can use a text editor or command-line tools to view the contents of the log file. Verify the Log File: Chrome cat /path/to/logfile.log Conclusion To conclude, environment variables play a crucial role in Linux as they help in configuring system behavior and applications. This guide offers a detailed explanation of how to set and manage environment variables for individual users and system-wide configurations. Additionally, it includes troubleshooting tips for popular browsers. Having a good understanding of environment variables and utilizing them effectively enhances flexibility and customization options within the Linux operating system.