/etc/profile: Explanation & Insights

Configure default settings for users

In Linux, the /etc/profile file is a system-wide configuration file that sets environment variables and aliases for all users when they log in. When a user logs in to the system, the shell reads the /etc/profile file to set up the initial environment.

Here are some examples of how the /etc/profile file can be used:

Setting the PATH variable:

The PATH variable is used by the shell to locate executable files. In the /etc/profile file, you can set the PATH variable to include directories containing executable files. For example, if you want to include the directory /usr/local/bin in the PATH, you can add the following line to /etc/profile:

export PATH=$PATH:/usr/local/bin

Setting aliases:

Aliases are shortcuts for frequently used commands. In the /etc/profile file, you can set aliases that are available to all users. For example, if you want to create an alias for the ls command that displays the files in color, you can add the following line to /etc/profile:

alias ls='ls --color=auto'

Setting environment variables:

You can set environment variables in the /etc/profile file that will be available to all users. For example, if you want to set the JAVA_HOME environment variable to the directory where Java is installed, you can add the following line to /etc/profile:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Running scripts:

You can also run scripts in the /etc/profile file. For example, if you have a script called myscript.sh in the directory /usr/local/bin that you want to run when users log in, you can add the following line to /etc/profile:

source /usr/local/bin/myscript.sh

In summary, the /etc/profile file is a system-wide configuration file that sets environment variables, aliases, and runs scripts for all users when they log in.

The text above is licensed under CC BY-SA 4.0 CC BY SA