'Alias yarn to yarnpkg to avoid conflict with Hadoop Yarn
I have Yarn (package manager) already installed on my machine, but I now have to install Apache Hadoop. When I tried doing that with brew install hadoop
, I got the error -
Error: Cannot install hadoop because conflicting formulae are installed.
yarn: because both install `yarn` binaries
Please `brew unlink yarn` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.
This seems to be because Hadoop's Yarn conflicts with yarn from yarnpkg.
As mentioned here, they have no intention of renaming yarnpkg's yarn, but they have added yarnpkg
as an alias to yarn
.
This SO answer just mentions using yarnpkg
instead of yarn
to avoid the conflict, but there's no steps on how to do so.
I'd appreciate any help on how to setup yarnpkg
alias so that I can install Hadoop alongside yarn.
Solution 1:[1]
I just solved it with unlinking and linking yarn again.
brew unlink yarn && brew link yarn
You can add an alias in .bashrc
or .zshrc
as follows
alias yarn='command yarnpkg'
Solution 2:[2]
I found that brew link yarn
as mentioned in the answer above won't work.
I speculated whether that might link only the non-conflicting yarnpkg
, but turns out it refused to link either, which seems quite fair.
Conceptually, (with yarn package manager unlinked) what you can do is add an alias to your .bash_profile like alias yarnpkg /usr/local/Cellar/yarn/1.22.0/bin/yarnpkg
Note that won't be robust to when you brew upgrade yarn to a new version.
Also, adding that directory to your path is not a good idea, because that makes ambiguous the fact you have two separate programs called yarn
installed.
An alternative to adding the bash alias is to just add the single, non-conflicting symlink manually in the same way brew link would do if it didn't refuse, as mentioned above:
ln -s /usr/local/Cellar/yarn/1.22.0/bin/yarnpkg /usr/local/bin/yarnpkg
It remains to be seen what happens when yarnpkg is updated, so keep an eye out for that. Since yarnpkg is not, apparently, symlinked by brew (except we sneakily added one), if brew doesn't update that symlink to point to the new version, then yarnpkg will stop working when you brew upgrade yarn
, unless you repeat the manual ln
as above pointing to the new version.
Update
Just tried it. Brew actually refuses to upgrade yarn, giving the reason that it conflicts with hadoop. So, we can brew unlink hadoop
, as it suggests, then brew upgrade yarn
.
Then, brew unlink yarn
, brew link hadoop
(hadoop has far more needed links than yarnpkg), then, finally, recreate the yarnpkg symlink with new version like so: /usr/local/Cellar/yarn/1.22.1/bin/yarnpkg
Quite long winded, but works fine.
Solution 3:[3]
Here is an easier way to solve this issue:
- install
hadoop
usingHomeBrew
- manually install
yarn
usingtarball
Step by step guide if already installed conflicting yarn
and hadoop
using Homebrew
:
Clean up conflict in Homebrew
and Install Hadoop
brew uninstall yarn
brew uninstall hadoop
brew install hadoop
brew link hadoop
(optional ifhadoop
is already installed byHomeBrew
but not linked)
Instal yarn
using tarball
brew install wget
(if does not have wget)cd /opt
wget https://yarnpkg.com/latest.tar.gz
(usesudo
if permission denied)tar zvxf latest.tar.gz
(usesudo
if permission denied)- open any of the following files
~/.profile
,~/.bash_profile
,~/.bashrc
,~/.zshrc
in the code editor to addyarn
to the path - Add these two lines
export PATH="$PATH:/opt/yarn-[version]/bin"
export PATH="$PATH:`yarn global bin`"
- see more on the yarn official doc
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nur Rony |
Solution 2 | mwal |
Solution 3 |