How to apend PATH variabale in Zsh?

How to apend PATH variabale in Zsh?


I know after installing homebrew, if i read .zprofile it says

~ % cat .zprofile 


eval "$(/opt/homebrew/bin/brew shellenv)"


But where exactly PATH string is being stored? So that i can apend at there.


Always a Linux and Windows user, very new to Mac.

MacBook Pro 16″, macOS 13.5

Posted on Sep 5, 2023 7:22 PM

Reply
13 replies

Sep 5, 2023 8:33 PM in response to ashutosh108

Environment variables are actually stored in process memory, and inherited by child processes. The inherited child process has their inherited environment variable list stored on the process stack.


Initial PATH values are established by the initial process PID 1, but then there are rules about looking at specific system shell initialization scripts that may modify the PATH along the way. There are some in /etc which are shell dependent (such as /etc/z* files). Etresoft has mentioned /etc/paths.d. And then there are the $HOME directory per user shell initialization scripts (such as $HOME/.z*)


If you have not established a specific PATH, then you get the standard process default, which is generally

export PATH="PATH=/usr/bin:/bin:/usr/sbin:/sbin"


If you actually look at what

brew shelling

is doing, it is creating export commands to add Homebrew environment variables, and in some cases it is modifying your existing environment variables, such as your exist PATH environment variable, which gets executed by the 'eval' command. This is what the Homebrew PATH setup command looks like:

export PATH="/usr/local/bin:/usr/local/sbin${PATH+:$PATH}";


Homebrew is a Unix/Linux style package manager for open source software, which is just like all the other Unix/Linux packages managers, in that it totally lacks great documentation, and easy to use operation.


Actually considering how much blog, YouTube, and other Internet coverage Apple gets, I would say Homebrew has better examples, and general support, then the getapp, yum, def, rpm, etc... package managers in the Unix/Linux world.


But in reality, if you are playing with Homebrew, then you should really have a grounding in the Unix/Linux world, or be prepared to do your homework, because any operating system command line is not going to hold your hand, and it is not going to simple minded.


I started working at an ASR33 Teletype back in the early '70's during college (along with 80 columns punched cards), and I have lived in the terminal world professionally for 50+ years, and I while I take a lot of the terminal based environment for granted, there is a lot that I have to do my own homework for, in order to do things. For example, I've been using Google to lookup some Perl syntax this week while I try to write a script that parses an ePub file for the Author's name.


If you are going to launch Applications -> Utilities -> Terminal, then do not expect it to be obvious in how to use it, nor any of the commands and utilities that come with macOS, nor 3rd party open source apps you install.

Sep 6, 2023 8:07 PM in response to Servant of Cats

Servant of Cats wrote:

Changing things forever, for all users, can be very risky if you do not know exactly what you are doing.

It’s very easy and totally safe, at least without Homebrew. Homebrew tends to completely corrupt the command line environment.

Even just messing up the setting of the PATH for your own account can potentially leave it broken enough that basic commands like ‘ls’ will not work unless you know where they live and type in full directory paths while you are going about fixing the mistakes in your shell initialization scripts.

An easy solution is to just keep multiple terminal windows open when editing those files. Then it is easy to open new windows, test, and fix any problems. And in a worst case scenario, Terminal has an option to launch a shell directly, bypassing any environment.


Well, I guess that’s not really a “worst case” scenario. The worst case scenario is when Homebrew is installed and then you are totally correct on all these points.

If you aren’t willing to do any work at all, or put ant thought at all, into your use of the command line environment, then it would be safest for you not to poke around at all in it.

But that is precisely Homebrew’s selling point. It’s quick and easy. People don’t have to learn anything about the Mac at all. But then when they get stuck, they are totally lost. None of the standard techniques work because Homebrew has so throughly trashed the system.

Sep 5, 2023 7:39 PM in response to ashutosh108

As far as paths and zsh go, the Mac is virtually identical to Windows. Probably the only difference I can think of if the macOS paths.d system for adding paths at the system level.


Your problem is with Homebrew. Although it is often recommended on the internet, it seems that it breaks much basic functionality. Then people come here asking for help. But Homebrew is 3rd party product. It would be nice if they provided some support, but they don’t. They expect people in this forum to support their product for free. But my only recommendation for Homebrew is to uninstall it.

Sep 5, 2023 9:13 PM in response to etresoft

etresoft wrote:

But Homebrew is 3rd party product. It would be nice if they provided some support, but they don’t. They expect people in this forum to support their product for free. But my only recommendation for Homebrew is to uninstall it.


From https://github.com/Homebrew/brew : "Homebrew is a non-profit project run entirely by unpaid volunteers." 


Like the people behind many other Open Source and Free Software projects, the people behind this project are making their work available free of charge to the community. (Although like many others, they will accept voluntary donations.)


They're not some commercial outfit profiting by using the Mac community as alpha-testers.


Sep 6, 2023 5:26 AM in response to Servant of Cats

Servant of Cats wrote:

From https://github.com/Homebrew/brew : "Homebrew is a non-profit project run entirely by unpaid volunteers." 

I never volunteered to support their product.

Like the people behind many other Open Source and Free Software projects, the people behind this project are making their work available free of charge to the community.

Which communities? As any of those open source advocates will tell you, there is more than one kind of "free". There is "free" as in "free speech" and "free" as in "free beer". What they provide is the "free beer", or rather, "free drugs" - to get people hooked and dependent.


Furthermore, these "free software" licenses are specifically designed so that they can only be used by the world's largest social media and information companies. People aren't donating their time to some nebulous community of techno-anarchists, they are donating their time to Google, Facebook, Amazon, Elon Musk, Netflix, etc. It is only these companies that have the financial resources to deploy millions of servers and sell services to people, and sell people's personal information to other corporations and governments, byte-by-byte.


Apple is different. Because Apple ships actual products to end users, only Apple is required to comply with these licenses and give away its work for free. That's not fair and that's why Apple doesn't play that GPL game.

(Although like many others, they will accept voluntary donations.)

But they expect non-voluntary support.

They're not some commercial outfit profiting by using the Mac community as alpha-testers.

Since when did profit become a bad word? Profit pays rent, feeds families, pays workers. Are these bad things? I would rather pay and be paid than be dependent on people who are wealthy enough that they don't have to work and instead choose to donate their time and effort to the most exploitative corporations in the world.

Sep 6, 2023 5:01 PM in response to BobHarris

Changing things forever, for all users, can be very risky if you do not know exactly what you are doing.


Even just messing up the setting of the PATH for your own account can potentially leave it broken enough that basic commands like ‘ls’ will not work unless you know where they live and type in full directory paths while you are going about fixing the mistakes in your shell initialization scripts.


If you aren’t willing to do any work at all, or put ant thought at all, into your use of the command line environment, then it would be safest for you not to poke around at all in it.

Sep 6, 2023 8:11 PM in response to Servant of Cats

Servant of Cats wrote:

You never volunteered to support Homebrew - and the people who put out Homebrew never volunteered your time to support it. If you don’t want to help Homebrew users who are having problems, don’t. Nobody is preventing you from helping out in the many, many threads that do not involve Homebrew, and simply ignoring any Homebrew-related threads.

Unfortunately, Homebrew has become virtually synonymous with use of the command line on the Mac. I don’t answer Homebrew questions other than to recommend people uninstall it. But usually, they don’t know how. They certainly didn’t install Homebrew because they could figure it out on their own.


I have noticed an increase in these kinds of posts where someone is struggling with some basic command line task. Homebrew is always involved - every single time.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to apend PATH variabale in Zsh?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.