Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nvm with yarn Yarn requires Node.js 4.0 or higher to be installed

Tags:

nvm

yarnpkg

I have nvm:

nvm ls
        v8.11.3
        v8.11.4
->      v11.1.0
default -> 8.11.4 (-> v8.11.4)
node -> stable (-> v11.1.0) (default)
stable -> 11.1 (-> v11.1.0) (default)

I installed yarn with:

sudo apt-get install --no-install-recommends yarn

I also added in .bashrc alias node=nodejs. But when I try yarn install I see:

Yarn requires Node.js 4.0 or higher to be installed.

How can I fix it?

like image 929
allay Avatar asked Nov 12 '18 16:11

allay


People also ask

Is Node.js required for yarn?

Yarn is a package manager for Node. It competes with NPM, not Node; both require Node. It is recommended to install Yarn through the npm package manager, which comes bundled with Node. js when you install it on your system.

Does NVM work with yarn?

When you install a new node version using nvm and then used npm to install yarn, you need to reinstall the yarn for the new node version. You can then switch between 8.11. 0 and 8.11. 3 and your yarn will still work.

Do I need to install Node for NVM?

To use it, you need to first install the bash script, and add it to your shell's $PATH . Learn more about why we recommend using NVM in Overview: Manage Node. js Locally. Note: We do not recommend using nvm to install Node.


1 Answers

First uninstall the nodejs package:

sudo apt remove nodejs

Ubuntu 16.04 contains a version of Node.js in its default repositories that can be used to easily provide a consistent experience across multiple systems. At the time of writing, the version in the repositories is v4.2.6. This will not be the latest version, but it should be quite stable and sufficient for quick experimentation with the language.

In order to get this version, we just have to use the apt package manager. We should refresh our local package index first, and then install from the repositories:

sudo apt-get update
sudo apt-get install nodejs

If the package in the repositories suits your needs, this is all you need to do to get set up with Node.js. In most cases, you’ll also want to also install npm, which is the Node.js package manager. You can do this by typing:

sudo apt-get install npm

This will allow you to easily install modules and packages to use with Node.js.

Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node. Keep this in mind as you are running software.

To check which version of Node.js you have installed after these initial steps, type:

nodejs -v

Screenshot for nodejs version

like image 52
Mohamed Raafat Avatar answered Sep 16 '22 17:09

Mohamed Raafat