0

I have previously installed npm, homebrew, oh-my-zsh and other runtime environments and worked perfectly on my Mac M1, until recently, no packages or runtime environments are being recognised.

When I enter brew I get error as zsh: command not found: brew but I can see in my opt/ path that there's homebrew folder and its content present,

Similarly for npm it shows error zsh: command not found: npm

I might have done something with my PATH

Here's a screenshotMac Terminal

Edit: My .bash_profile is empty, should it be empty?? .bash_profile

Atharva
  • 127
  • 1
  • 2
  • 10
  • I think brew usually installs packages in `/opt/local/bin`, which you don't have in your `$PATH` – Barmar Nov 11 '21 at 17:33
  • I uninstalled and reinstalled homebrew but it still is in MacintoshHD/opt/homebrew. There is no 'local' folder in /opt – Atharva Nov 11 '21 at 19:35
  • Does your mac have an Intel processor or is it the newer Apple silicon? The homebrew installation directories are different (Intel -> `/usr/local`, M1 -> `/opt/homebrew`). It looks like you have combination of both. – Gairfowl Nov 12 '21 at 01:00
  • I have M1 and the path is /opt/homebrew – Atharva Nov 12 '21 at 08:07
  • `.bash_profile` is irrelevant, as you aren't using `bash`. – chepner Nov 13 '21 at 19:33

1 Answers1

1

On the M1 Macs, homebrew files are installed by default in /opt/homebrew, and the executables are usually placed in or linked to /opt/homebrew/bin. That directory is not in your search PATH - instead, it looks like you have the PATH settings for an Intel Mac.

As you noted, updating the PATH should fix the issue, but first you need to determine which shell you are using (the question is tagged both zsh and bash). It's probably zsh, since that's the default on newer versions of macOS, and it would explain why the .bash_profile is empty. You can double-check this with the command echo $0.

There are several ways to update the path, and many are described in other posts here at SO, such as this one. This will also work for zsh:

print 'PATH=$PATH:/opt/homebrew/bin' >> ~/.zshrc
Gairfowl
  • 2,226
  • 6
  • 9
  • I may have accidentally used some code on stack overflow of Mac Intel while doing some troubleshooting, is there anything I can do to repair my PATH settings of M1 Mac not only for homebrew but for any further downloads? – Atharva Nov 12 '21 at 13:39
  • Having `/opt/homebrew/bin` in the PATH should cover the `brew` command and most packages that are installed that way. For other downloads, you'll need to follow their recommendations. And of course, backups (e.g via Time Machine) are always useful for getting back to a known working state when something goes wrong. – Gairfowl Nov 13 '21 at 01:19