Alias yarn to yarnpkg to avoid conflict with Hadoop Yarn - hadoop

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.

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'

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.

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
brew uninstall yarn
brew uninstall hadoop
brew install hadoop
brew link hadoop(optional if hadoop is already installed by HomeBrew but not linked)
Instal yarn using tarball
brew install wget (if does not have wget)
cd /opt
wget https://yarnpkg.com/latest.tar.gz (use sudo if permission denied)
tar zvxf latest.tar.gz (use sudo if permission denied)
open any of the following files ~/.profile, ~/.bash_profile, ~/.bashrc, ~/.zshrc in the code editor to add yarn 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

Related

Anything installed via homebrew throws 'command not found'

I've recently had some issues setting up my new mac with homebrew and npm. I've installed npm and node via nvm (not homebrew). For example, I installed yarn via homebrew and when i run yarn i get bash: yarn: command not found however if i run brew list I see yarn as one of the installations.
I have read that this usually has to do with my path being incorrect however I do see /usr/local/bin in my $PATH when I echo: /Users/sydney/.nvm/versions/node/v8.11.3/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Do I need to change the path order? Will this break any dependencies for nvm? This is not just happening for yarn but any package i install via homebrew (I've just attempted to install kubernetes-cli with the same results)

Why doesn't yarn updated when running upgrade?

I'm trying to use latest yarn version after upgrading it.
I've follow over https://yarnpkg.com/en/docs/install#mac-stable instructions, but yarn didn't really upgraded.
After running brew upgrade yarn:
$ brew upgrade yarn
Updating Homebrew...
Error: yarn 1.9.4 already installed
And after running yarn --version:
$ yarn --version
1.9.2
Is there any way to use the latest version?
Although the guide says that brew upgrade yarn should do it automatically..
There's a lengthy thread on Github regarding upgrades; here's what is suggested for HomeBrew:
brew upgrade yarn
brew link --overwrite yarn
Then try yarn -v
If that fails then you could:
First, uninstall brew's yarn:
brew uninstall yarn
Removing yarn binaries manually:
rm -f /usr/local/bin/yarnpkg
rm -f /usr/local/bin/yarn
Remove yarn cache:
rm -rf ${HOME}/.yarn
If you have the following in your .zshrc or .bash_profile, remove it:
export PATH="$PATH:`yarn global bin`"
Install via curl:
curl -o- -L https://yarnpkg.com/install.sh | bash
Make sure there is the following line in your .zshrc or .bash_profile:
export PATH="$HOME/.yarn/bin:$PATH"
↳ Github : yarn update discussion thread
If you installed yarn with npm in an nvm environment then you can just run npm -g upgrade yarn. To check that run which yarn -- if you see .nvm in the result of that, you are in an nvm environment.

Brew older version of mysql not available at cmd line

I've installed mysql 5.7 via brew. The binary files are installed at /usr/local/opt/mysql\#5.7/bin/ however I can't access these files as this location isn't in my path.
Is there a brew way to fix this rather than me making symlinks around the system myself?
The Homebrew way of "fixing" this is to use link --force:
brew link --force mysql#5.7
Alternatively, you can add this location to your $PATH by modifying it in your ~/.bashrc or ~/.bash_profile:
export PATH="$(brew --prefix mysql#5.7):$PATH"
The simple "brew way" to do this is answered here
$ brew info mysql (to get info about the installed versions)
$ brew switch mysql 5.7.21 (to switch to a stable version)

Can't reinstall or uninstall Homebrew after blowing away contents of /usr/local/bin

I removed ALL content from /usr/local/bin folder (including 'brew'). Homebrew isn't working anymore and I seem to be stuck in a limbo. When I try to install it says:
It appears Homebrew is already installed. If your intent is to
reinstall you should do the following before running this installer
again:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
When I run the given uninstall command it says:
Failed to locate Homebrew!
Background
The problem arose when I attempted to remove node.js by following this guide:
https://stackoverflow.com/a/11178106/1736012
To completely uninstall node + npm is to do the following:
go to /usr/local/lib and delete any node and node_modules
go to /usr/local/include and delete any node and node_modules directory
if you installed with brew install node, then run brew uninstall node in your terminal
check your Home directory for any local or lib or
include folders, and delete any node or node_modules from there
go to /usr/local/bin and delete any node executable
Especially 5 was bad! That's what led me to remove everything under /usr/local/bin. So brew doctor won't work (brew isn't recognized anymore). Brew worked fine before this.
What I tried
This does not work either as brew is missing:
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"
I tried various scripts like this one for example: https://apple.stackexchange.com/a/85481. And this: https://gist.github.com/SteveBenner/11254428. None of them is working (both assumes that brew command is there)...
What can I do to re install Homebrew so that it works as before??
This should bring back a working brew command:
cd /usr/local/Homebrew
git init
git remote add origin https://github.com/Homebrew/homebrew
git pull origin master
Next I would check the output of brew doctor and see if there are major problems. There is an official uninstalling guide on homebrew's github wiki in case you want to completely uninstall.
Try to move or remove the Homebrew file in the user/local file and then try the regular link from the homebrew homepage to install the brew!
By the way, I did not try moving but I am pretty sure it should work.
Note: While the operation you might have to use the sudo
I faced the same issue, the following link really worked for me
https://github.com/Homebrew/brew/issues/10368
especially comment from MrBenFTW commented on Feb 2021

Ruby error Homebrew uninstall while having macports

I installed ruby via \curl -L https://get.rvm.io | bash -s stable and did rvm install 1.9.2 doing this creates and error
Installing requirements for osx, might require sudo password.
fatal: Unable to create '/usr/local/.git/index.lock': Permission denied
Error: Failure while executing: git checkout -q master
Failed to update Homebrew, follow instructions here:
https://github.com/mxcl/homebrew/wiki/Common-Issues and make sure `brew update` works before continuing.
Upon doing a which git it shows it's installed in /usr/bin/git yeah homebrew keeps trying to reference /usr/local/.git. I tried unistalling homebrew so I can do a fresh install using what's listed at homebrew gist. All seemed well but doing a which brew still shows it as /usr/local/bin/brew so I tried to manually uninstall it by doing it one by one.
One thing to note is I never had a Cellar folder, why I don't know. While doing a brew prune I noticed a lot of macport items are starting to ask if I should override them.
Is it typical to of ran the uninstall script but still have the brew commands available or the dirs?
Why is it that homebrew needs root access to /user/local/ to work, this is extremely bad.
That /usr/local/.git it's referencing is not the git executable, but the config file for the repository it's trying to set up under /usr/local/. It's trying to write to that file.
To run homebrew you need write permissions to /usr/local as the user you'r going to run brew as. Homebrew's recommended method is to adjust the ownership and permissions on /usr/local to allow you to write to it from your regular user account or a dedicated homebrew account, instead of using sudo. This is done as part of the homebrew installation script, typically by putting you in the admin group and making /usr/local group-writable.
To fix this, check the owner and permissions on /usr/local/ and /usr/local/.git and make sure you can write to them (and the rest of the /usr/local/ hierarchy) as the user that you're running brew and RVM commands as.
Ended up just doing a sudo $USER as I really could not find any other approach to fixing this.

Resources