Setting environment variables in both Bash and Zsh is a straightforward process. However, there is a slight difference when it comes to persisting them. In Bash, you can use the .bashrc file, while in Zsh, you can use the .zshrc file.

To set environment variables in the shell, follow these steps:

  1. Open your terminal and type the following command:

    $ export VARIABLE=something
    

    This command sets the value of the variable “VARIABLE” to “something”.

  2. To ensure that the variable was set correctly, you can check its value by typing:

    $ echo $VARIABLE
    

    This command will display the value of the “VARIABLE” variable.

  3. If you make changes to a dot file (e.g., .bashrc or .zshrc), you need to apply the changes to the current shell session using the source command. For example:

    $ source .bashrc
    

    This command reloads the “.bashrc” file and applies the changes without the need to restart the shell.

The steps outlined above are applicable for both Bash and Zsh.

For Fish shell users, the process is slightly different. To set environment variables in Fish, you need to prepend the env command. For example:

env API_KEY=123123 node app.js

This command sets the “API_KEY” environment variable to “123123” and runs the “app.js” script using Node.js.

By following these steps, you can easily set environment variables in Bash, Zsh, and Fish shells.

Tags: environment variables, Bash, Zsh, Fish shell