What's the difference between installing Yarn from npm, Homebrew, and from source? - macos

I read that on OS X you can install Yarn either by
curl -o- -L https://yarnpkg.com/install.sh | bash
brew install yarn
npm i -g yarn
What functional difference is there between these three methods? Why would someone choose one over the others?

when using brew to install packages, you install them system wide. that is, you cannot have more than one version for the same package, which is usually problematic. for this reason, many other technologies have spawn, such as docker, snap.
moreover, each package manager has its own lifecycle and packs original package in a different manner for ease of use, distribution and maintenance. for instance, npm container is based on the release of npm package itself.
usually, you should stick to the package manager of the same ecosystem that you are using. specifically to your case, it will be recommended to use npm to install and update your package (using package.json). which will give each of your project to pin and lock the desired yarn version that you like, without any affecting your system wide.
speaking of npm, you might wish to look at this answer

curl downloads the installation script from yarnpkg.com, and installs yarn using that script
brew is a package manager for MacOS. It's meant to make things easier for people when installing commands for the terminal. When you install with brew, the package get's put into /usr/local/bin instead of /usr/bin so I believe that this is kind of like a virtual environment, and yarn wouldn't be installed into the core of your machine. You'll have to install homebrew before you can use it, and you install it using curl. I believe that there is less risk when using homebrew because of the reasons that it is kind of like a virtual environment
npm is a package manager for javascript, it's the same as yarn. It's meant for easy installation of javascript packages.
I use brew for all installs to the terminal, and npm for all installs of javascript packages.

Related

Packages apt-get vs brew?

Im trying to get something running in a lab, and I need to install a whole bunch of packages to compile the code:
sudo apt-get install build-essential libgtk2.0-dev libwxgtk3.0-dev libwx-perl libmodule-build-perl git cpanminus libextutils-cppguess-perl libboost-all-dev libxmu-dev liblocal-lib-perl wx-common libopengl-perl libwx-glcanvas-perl libtbb-dev libxmu-dev freeglut3-dev libwxgtk-media3.0-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libcurl4-openssl-dev libextutils-makemaker-cpanfile-perl
The problem is, I'm working on a Mac; So I only have brew available - and the package names are not equivalent.
Am I trying to do something dumb and impossible, or is there a way to cross reference those apt-get packages to ones available in brew and install those so I can build the app?
For added context, its a modified "slicer" application for generating files that a 3d printer uses to make parts. I could fire up an ubuntu VM and use apt-get, but I'm on an M1 mac at the moment and recompiling experimental QEMU code just so I can fire up an ubuntu VM takes me way more out of my depth than I already am... I'm running brew on a duplicated, rosetta emulation forced terminal.
There is no straightforward way to automatically figure out whether a corresponding Homebrew package exists for each of these packages, no. But you can probably guess the majority, and manually figure out the rest. Each Debian package has a link to the upstream sources, and a home page if one exists, from which you can often find links to packages for other architectures, etc.
From the Debian package search page you can search e.g. for the libxmu-dev package, and discover the corresponding package page for Buster (the current stable Debian release), which in turn has links to the upstream repo, etc. But this is an X11 package, so it's not straightforwardly compatible with macOS, which uses an entirely different GUI architecture.

macOS Package Managers: Using Nix alongside Homebrew?

I was wondering if there would be any issues with installing Nix and Homebrew on the same system?
I know Homebrew tends to install things all over different directories, but from what I have read, Nix is very clean. If I understand this correctly, Nix installs it's packages all within one single directory.
So if this is the case, could I try running them both side-by-side? I would be careful not to install too many of the same packages from both places in (ie. I wouldn't install grep, htop, or whatever else from both Homebrew and Nix and if I did I would take precautions).
Side-note: This would not be permanent. I am thinking about switching from Homebrew to Nix (just to mix things up a bit), and I wanted to try Nix on my main machine before taking the leap (if at all). I know I could just try Nix on a VM, but I would not get the same experience unless I tried it on my main system. So it would be nice to install it along Homebrew and give it a shot before going through the pains of removing Homebrew and replacing all my Homebrew packages with Nix packages.
Yes, you can install Nix along side Homebrew.
Nix will install all it's packages within /nix/store For example, on my NixOS system vim is currently installed in /nix/store/j6nrk9h1rpxrzmccm0yq520ik625gd1q-vim-8.1.0578
Your shell will choose whether to use a package from Nix or Homebrew, according to how $PATH is set up. For example, if it so happens that the Nix paths are first, then they will take precedence.
Note
A common source of confusion is that install means something different on Nix. When you install a package, such as Python, it becomes part of a Nix environment, and as such can be executed without specifying the full path; Just as you'd expect from any package manager.
However, if you install a package which has, say, Python, as a dependency, Python would get installed, but more likely than not it would not be included in the environment. Hence it can only be executed via the absolute path.
On a related note, due to a similar reason, if you install a library with Nix and then try to compile against it outside of Nix, it will not work; The build tools will not find the library.

Automatically install pip packages' OS dependencies

I am installing lots of pip packages on a debootstrap'd Debian which is understandably quite bare bones and lacks a ton of packages that you'd usually expect on a regular installation. Naturally, pip installations are failing because the OS doesn't have the libraries they depend on.
Instead of individually digging for dependencies I need to install, is there a way to let pip resolve apt dependencies?
No. pip is a portable tool designed to be run on many operating systems. But on every operating system pip works with just Python packages and doesn't touch system libraries. If you install Python packages with apt or any other distribution-specific package manager it handles all dependencies. When you add pip to the toolbox — you are on your own.

IPython3 for Mac OSX

I have Ipython installed but it runs on python 2.7.5 , I also have python 3.3 installed. How can I make changes such that Ipython runs on python 3.3 not 2.7.5?
You need to install pip for Python 3 - it's as easy as going to the pip-installer.org Installation page and following the instructions. Briefly, download get-pip.py and save it someplace, like your Downloads folder. Navigate there in Terminal, and run
sudo python3 get-pip.py
and you should soon have either a pip3 or pip-3.3 command (maybe both, I don't remember). You should now be able to run
sudo pip3 install ipython[all]
and hopefully all the dependencies will be installed as well. If installation chokes, use pip3 to install pyzmq, tornado, pyreadline, jinja2, pygments, and maybe a few others. Make sure you read the docs before you start, so you have an idea of what you're trying to achieve. IPython is large and quite complex, with many moving parts, so in the absence of a package manager (see below) it can take a bit of time before everything is up and running.
The Package Manager Way
There are other options, too. You can install Anaconda, a "Completely free enterprise-ready Python distribution for large-scale data processing, predictive analytics, and scientific computing" with over 100 packages, including IPython and its dependencies. By default, the Anaconda installer gives you Python 2.7, but you can use the conda command to install Python 3.
My personal favorite is to install Python 3 and IPython using MacPorts. Yes, it'll install Py3 all over again, but unless you're really starving for disk space (in which case you probably don't want to be installing large packages like IPython) it's no big deal. Using the port command, once the base MacPorts installation has been put in place, you can just run
sudo port install py33-ipython +pyqt4
and all the other dependencies will be taken care of, (hopefully) flawlessly, without your having to do anything else except wait for a long time while things like PyQt are compiled. You may also need to run sudo port install py33-ipython +notebook if you want the notebook, I don't recall if it's installed otherwise. BTW, you do need X11, Xcode, and the Xcode command-line tools for MacPorts, but they would likely be required if you do the first option as not all packages have binaries available for OS X. The excellent documentation walks you through everything, from installation to using the port command to maintaining your system. I would highly recommend modifying your ~/.profile (or ~/.bash_profile, ~/.bashrc, or equivalent for your shell) to add the MacPorts install directories (/opt/local/bin and /opt/local/sbin, by default) to the front of your path. Just add export PATH='/opt/local/bin:/opt/local/sbin:$PATH' to the end of the file.
A third alternative option is to use Homebrew. It's similar to MacPorts, in that the brew command is a type of package manager like port and conda, but in my experience it doesn't have as many packages, and doesn't quite work as seamlessly as port. However, my observations on StackOverflow, Ask Different and other fora seem to indicate that about 50% of people have great experiences with brew and don't like port, while the other half loves port over brew. YMMV.
I hope this helps. Good luck with your installation!

npm global path prefix

I am being more cautious than usual because I have been confused by the behavior of npm in the past.
I am on a Mac and have installed node.js through brew install node.
Now that I want to run jslint.js on the command-line as the command jslint I find that the canonical way to accomplish this is sudo npm install -g jslint which ran successfully with this output:
$ sudo npm install -g jslint
npm http GET https://registry.npmjs.org/jslint
npm http 200 https://registry.npmjs.org/jslint
npm http GET https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz
npm http 200 https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz
npm http GET https://registry.npmjs.org/nopt
npm http 200 https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http 200 https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http GET https://registry.npmjs.org/abbrev
npm http 200 https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/abbrev/-/abbrev-l.0.4.tgz
npm http 200 https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz
/usr/local/share/npm/bin/jslint -> /usr/local/share/npm/lib/node_modules/jslint/
bin/jslint.js
jslint#0.1.9 /usr/local/share/npm/lib/node_modules/jslint
└── nopt#1.0.10 (abbrev#1.0.4)
Subsequently
$ jslint ply.js
zsh: command not found: jslint
due to /usr/local/share/npm/bin not being in my $PATH.
1) Why did brew not install global npm bin path to path? Maybe it did, but something zsh does is messing it up. Where might I be able to find that?
2) Should I do this? (Append :/usr/local/share/npm/bin to the exported $PATH at the bottom of my ~/.zshrc)
It seems like this isn't the right way to do it because if I install something else later (using Homebrew or something) I'll be needing to append it to my zsh startup script to set the path. I guess in this particular instance it's just a matter of the npm install -g not making the right symlinks in a "proper" location (like /usr/local/bin maybe).
I think what I will do is manually build out symlinks inside /usr/local/bin for any programs that I have trouble with and it should be good enough for my purposes.
EDIT: I'm updating this in 2019, because this old question is popular but now outdated both in terms of my personal workflow and also in terms of how to best go about installing node and managing its various dependencies.
My personal workflow is now to use the installer obtained from nodejs.org to install node on systems. I actually trust this more than the homebrew package itself, because it knows best how to manage the files. If you want to change your system node from 8.10 to 10.15, whether on Mac or Windows, simply download the installer from nodejs.org for 10.15 for your OS. Attempting to upgrade node installed via homebrew has always proven to be a more difficult approach in my experience.
Also, the biggest thing to point out is that the use of sudo as shown in my npm install of jslint example above is highly discouraged; I am fairly certain that homebrew packages should never be installed or interacted with in any way using the superuser. It should not be necessary, and will lead to file permission headaches!
Furthermore I recommend ESLint over jslint, and have not used jslint in years.
Extending your PATH with:
export PATH=/usr/local/share/npm/bin:$PATH
isn't a terrible idea. Having said that, you shouldn't have to do it.
Run this:
npm config get prefix
The default on OS X is /usr/local, which means that npm will symlink binaries into /usr/local/bin, which should already be on your PATH (especially if you're using Homebrew).
So:
npm config set prefix /usr/local if it's something else, and
Don't use sudo with npm! According to the jslint docs, you should just be able to npm install it.
If you installed npm as sudo (sudo brew install), try reinstalling it with plain ol' brew install. Homebrew is supposed to help keep you sudo-free.
Spent a while on this issue, and the PATH switch wasn't helping. My problem was the Homebrew/node/npm bug found here - https://github.com/npm/npm/issues/3794
If you've already installed node using Homebrew, try ****Note per comments that this might not be safe. It worked for me but could have unintended consequences. It also appears that latest version of Homebrew properly installs npm. So likely I would try brew update, brew doctor, brew upgrade node etc before trying****:
npm update -gf
Or, if you want to install node with Homebrew and have npm work, use:
brew install node --without-npm
curl -L https://npmjs.org/install.sh | sh
I use brew and the prefix was already set to be:
$ npm config get prefix
/Users/[user]/.node
I did notice that the bin and lib folder were owned by root, which prevented the usual non sudo install, so I re-owned them to the user
$ cd /Users/[user]/.node
$ chown -R [user]:[group] lib
$ chown -R [user]:[group] bin
Then I just added the path to my .bash_profile which is located at /Users/[user]
PATH=$PATH:~/.node/bin
I managed to fix Vue Cli no command error by doing the following:
In terminal sudo nano ~/.bash_profile to edit your bash profile.
Add export PATH=$PATH:/Users/[your username]/.npm-packages/bin
Save file and restart terminal
Now you should be able to use vue create my-project and vue --version etc.
I did this after I installed the latest Vue Cli from https://cli.vuejs.org/
I generally use yarn, but I installed this globally with npm npm install -g #vue/cli. You can use yarn too if you'd like yarn global add #vue/cli
Note: you may have to uninstall it first globally if you already have it installed: npm uninstall -g vue-cli
Hope this helps!
brew should not require you to use sudo even when running npm with -g. This might actually create more problems down the road.
Typically, brew or port let you update you path so it doesn't risk messing up your .zshrc, .bashrc, .cshrc, or whatever flavor of shell you use.
In newer MacOS versions you need to edit the .zshrc file not .bash_profile:
In your terminal nano ~/.zshrc
then add the line:
export PATH=$PATH:/Users/[your username]/.npm-packages/bin
Try running:
PATH=$PATH:~/npm/bin
and then do a test by running express in the command line. This worked for me.
If you have linked the node packages using sudo command
Then go to the folder where node_modules are installed globally.
On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\Application Data\npm\node_modules
Windows 7 - %AppData%\npm\node_modules
and then run the command
ls -l
This will give the list of all global node_modules and you can easily see the linked node modules.
sudo brew is no longer an option so if you install with brew at this point you're going to get 2 really obnoxious things:
A: it likes to install into /usr/local/opts or according to this, /usr/local/shared. This isn't a big deal at first but i've had issues with node PATH especially when I installed lint.
B: you're kind of stuck with sudo commands until you either uninstall and install it this way or you can get the stack from Bitnami
I recommend this method over the stack option because it's ready to go if you have multiple projects. If you go with the premade MEAN stack you'll have to set up virtual hosts in httpd.conf (more of a pain in this stack than XAMPP)plust the usual update your extra/vhosts.conf and /etc/hosts for every additional project, unless you want to repoint and restart your server when you get done updatading things.
Any one got the same issue it's related to a conflict between brew and npm
Please check this solution https://gist.github.com/DanHerbert/9520689
I uninstalled node from homebrew on M1 Apple Silicon and instead used the Mac Installer from https://nodejs.org/en/download/. After doing that I was able to install with npm and npx.
Simple solution is ...
Just put below command :
sudo npm config get prefix
if it's not something like these /usr/local, than you need to fix it using below command.
sudo npm config set prefix /usr/local...
Now it's 100% working fine

Resources