When dealing with MacOS and Angular, I know that you can install node/npm with Homebrew, and I know that you can use npm install -g @angular/cli
to install Angular globally amongst your node environments.
Setting up a new machine I recently discovered there was an angular-cli
homebrew formula. I am not super familiar with the general architecture of Homebrew and how it works, and what I have not been able to find is any discussion on the benefits of installing it one way or the other.
I typically try to subscribe to a "anything you can install with the main package manager do so", but am curious on the approach here as I'm not really sure the value of this as a brew formula.
What are the practical differences? If any? Disadvantages/advantages of one over the other?
Curiosity points:
- Updating - updating angular CLI now coupled to whether or not there is an updated formula for the update not just a new node package available?
- Install location - I know on other machines I have had to point pycharm to specific globally installed packages, where would it be referenced from?
- Other globally installed packages - If there is not a homebrew formula for some other package that should be globally installed, is it still installed in the same location as the ones managed with Homebrew or is it treated differently?
I know there's lots on how to install Angular CLI, but nothing I could find had this particular discussion/comparison.
CodePudding user response:
My experience with angular is somewhat limited, but I'll try to answer the question as best as I can.
Assuming you are installing the angular-cli npm package globally, there aren't too many differences:
Homebrew:
- If you just want it to work, Homebrew is sometimes easier.
- "One tool to rule them all" - Unified approach to updating your system CLTs. Ironically, it even sets up npm for you.
NPM:
- Ability to receive the latest update as soon as it's published.
- If you didn't install node via Homebrew, this method leads to less duplication. This is since Homebrew will install it's own version of node/npm to install angular-cli.
- This might lead to surprises about which npm you're using depending on how your path is configured.
All Homebrew is doing behind the scenes is running npm install
and symlinking the binary to your prefix (normally /usr/local/bin
on intel machines).
From the Homebrew formula:
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
bin.install_symlink Dir["#{libexec}/bin/*"]
Updating - updating angular CLI now coupled to whether or not there is an updated formula for the update not just a new node package available?
Exactly. Installing using brew means you have to wait for the Homebrew formula to be updated before you can update. Installing with npm gives you the updated version as soon as it's published.
From personal experience however, the homebrew formula will likely be updated very quickly.
Install location - I know on other machines I have had to point pycharm to specific globally installed packages, where would it be referenced from?
The path of angular-cli will be $(brew --prefix)/bin/ng
, where the default prefixes are:
/usr/local
on Intel/opt/homebrew
on Apple Silicon
Other globally installed packages - If there is not a homebrew formula for some other package that should be globally installed, is it still installed in the same location as the ones managed with Homebrew or is it treated differently?
I don't quite understand, but I'll try to answer what I think your question is:
If I install an npm package globally, is it installed in a different location to the homebrew angular-cli?
Yes. All the Homebrew files will be installed into $(brew --prefix)/Cellar
, so angular-cli will be installed into. $(brew --prefix)/Cellar/angular-cli/
The binary will be symlinked to $(brew --prefix)/bin
.
Your npm packages might be installed into $(brew --prefix)/lib/node_modules
, or maybe ~/.nvm/
depending on how you're doing things.
Does this make a difference? Assuming these global packages are all CLTs, then no since they should all be in your PATH anyway.
Feel free to ask any questions and I'd be happy to help :)