How to Fix yarn requires node.js 4.0 or higher to be installed

Yarn requires node.js 4.0 or higher to be installed warning occurs when you try to install yarn package manager but use Node.js version below version 4.0.

To fix the yarn requires node.js 4.0 or higher to be installed error, “install the latest version of Node.js or upgrade your current Node.js version to the latest version.”

Once you have Node.js installed, you can install Yarn using the following command (using npm, which is bundled with Node.js.

npm install -g yarn

This will install Yarn globally on your machine.

You can also use the below approach to install yarn on your machine.

echo "==> Installing Yarn package manager"

rm -rf ~/.yarn

curl -o- -L https://yarnpkg.com/install.sh | bash

# Yarn configurations
export PATH="$HOME/.yarn/bin:$PATH"

yarn config set prefix ~/.yarn -g

To run these commands:

  1. Open a terminal or command prompt.
  2. Copy and paste each command, pressing Enter after each one.
  3. Follow any on-screen instructions.

Always ensure you trust the source before executing any script. If you’re unsure, you can always review the script’s content first by downloading and inspecting it.