How to add a new entry to the PATH variable in ZSH on Mac OS in Linux

LinuxOperating SystemOpen Source

By default, we don’t have the .zshrc file present in macOS Catalina, and we need to create it. In order to create the .zshrc file, we can follow the steps shown below −

  • Open Terminal

  • Type touch ~/.zshrc to create the file.

  • Hit Return

We can also open the .zshrc file in the terminal from any directory by just typing the command shown below

Example

vi ~/.zshrc

Output

immukul@192 linux-questions-code % cat ~/.zshrc
export GOPATH=/Users/immukul/go_projects
export NDHOME=/Users/immukul/Downloads
export GOTRACEBACK=all
export GOROOT=/usr/local/go
export LC_CTYPE=C
export PATH=/home/Systems
export LANG=C

It should be noted that the output may vary from machine to machine.

To add an entry to the PATH variable present inside the we can write the following command to the terminal, and we don’t even have to open the zshrc file to do that.

Command

echo -n 'export PATH=~/some/path:$PATH' >> ~/.zshrc

Output

immukul@192 linux-questions-code % cat ~/.zshrc
export GOPATH=/Users/immukul/go_projects
export NDHOME=/Users/immukul/Downloads
export GOTRACEBACK=all
export GOROOT=/usr/local/go
export LC_CTYPE=C
export PATH=/home/Systems:/some/path
export LANG=C

Another approach is to open the zshrc file and then insert the export command manually.

Command

export PATH=/home/bin:$PATH

Output

immukul@192 linux-questions-code % cat ~/.zshrc
export GOPATH=/Users/immukul/go_projects
export NDHOME=/Users/immukul/Downloads
export GOTRACEBACK=all
export GOROOT=/usr/local/go
export LC_CTYPE=C
export PATH=/home/Systems:/some/path:/home/bin
export LANG=C

It is recommended to source the file once you are done to make the changes available to all the terminals.

raja
Published on 29-Jul-2021 10:51:56
Advertisements