The Node.js platform is gaining more and more popularity. In addition to the default package manager called npm, there is another advanced package manager for this platform called yarn. It allows you to install, uninstall and update packages.
Yarn is compatible with npm, so this package manager can be used with npm. It uses the same package.json configuration file. Let's see how to install Yarn Ubuntu using the 20.04 version of the distribution as an example.
It is quite easy to install the program in Ubuntu. True it is not in the official repositories, so you will have to add a developer repository. To do this, you will need the curl utility. Install it if it is not already installed:
$ sudo apt install curl
Now you can import the repository's GPG key. To do this, execute:
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
After adding the key, add the repository to the /etc/apt/sources.list.d/yarn.list file. This can be done manually or with a command like this:
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Then update the package lists:
$ sudo apt update
And the only thing left to do is to install yarn:
$ sudo apt install yarn
You can view the version of the installed program with this command
$ yarn --version
To create a new project go to the project folder and run this command:
$ yarn init project_name
While creating the project, the package manager will generate package.json and to generate it you will need to answer a number of questions. Although you can leave all the default values. To install a package you should use the add command. The syntax is as follows:
$ yarn add pocket_name@version
For example, to install the vue package, run the command:
$ yarn add vue@latest
Once the package is installed, you can use it. You can see the contents of the package.json file:
$ cat package.json
To remove packages use the remove command:
$ yarn remove pocket_name
To update all installed dependencies use the upgrade
command:
$ yarn upgrade
If you have downloaded a ready-made project, to install all its dependencies written in package.json use this command:
$ yarn install
Now you know how Yarn Ubuntu installation is done