Alias yarn to yarnpkg to avoid conflict with Hadoop Yarn
Asked Answered
A

4

7

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.

Abb answered 1/3, 2019 at 1:20 Comment(2)
Just wondering if you've found instructions on setting up yarnpkg alias?Refrigerate
@user8888 You have to add the yarn /bin folder to you PATH environment variableLudhiana
C
0

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'
Chico answered 28/1, 2020 at 17:45 Comment(0)
G
0

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.

Galosh answered 8/3, 2020 at 16:3 Comment(0)
M
0

Here is an easier way to solve this issue:

  • install hadoop using HomeBrew
  • manually install yarn using tarball

Step by step guide if already installed conflicting yarn and hadoop using Homebrew:

Clean up conflict in Homebrew and Install Hadoop

  1. brew uninstall yarn
  2. brew uninstall hadoop
  3. brew install hadoop
  4. brew link hadoop(optional if hadoop is already installed by HomeBrew but not linked)

Instal yarn using tarball

  1. brew install wget (if does not have wget)
  2. cd /opt
  3. wget https://yarnpkg.com/latest.tar.gz (use sudo if permission denied)
  4. tar zvxf latest.tar.gz (use sudo if permission denied)
  5. open any of the following files ~/.profile, ~/.bash_profile, ~/.bashrc, ~/.zshrc in the code editor to add yarn to the path
  6. Add these two lines
    export PATH="$PATH:/opt/yarn-[version]/bin"
    export PATH="$PATH:`yarn global bin`"
  7. see more on the yarn official doc
Montoya answered 22/4, 2022 at 1:48 Comment(0)
G
0

I have

hyarn () {
        alias yarn=/opt/homebrew/bin/yarn
}

jyarn () {
        alias yarn=/usr/local/bin/yarn
}

jyarn
export PATH="$(yarn global bin):$PATH"
hyarn

I have this in my dot file to context switch between the two yarn commands. And I am exporting the functions hyarn and jyarn as

export hyarn
export jyarn

Stays very handy for me.

For example, for Hadoop yarn

fahad in ~ λ hyarn
fahad in ~ λ yarn
Usage: yarn [OPTIONS] SUBCOMMAND [SUBCOMMAND OPTIONS]
 or    yarn [OPTIONS] CLASSNAME [CLASSNAME OPTIONS]
  where CLASSNAME is a user-provided Java class

  OPTIONS is none or any of:

and for yarn for JS

fahad in ~ λ jyarn
fahad in ~ λ yarn
yarn install v1.22.10
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.05s.
Gibran answered 7/7, 2023 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.