We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

27
751.065,85

Cart

Quantity 2.750,00
Quantity 11.444,40

How to Install Yarn Package Manager on Ubuntu – Cloudbooklet

How to Install Yarn Package Manager on Ubuntu. Yarn is a JavaScript package manager that helps you automate the process of installing, updating, configuring, and removing npm packages easily. It also speeds up the process of the package installation and also prevents the errors related to network connectivity.

In this guide you are going to learn how to install Yarn on Ubuntu and also go through the commands of yarn to update, upgrade and remove the packages.

This setup is tested on Google Cloud Platform, so it will work on any cloud hosting services like AWS, Azure or any VPS or Dedicated servers running Ubuntu OS.

Install Yarn on Ubuntu

Enable the Yarn repository by importing the GPG key using the following command.

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

Now you can add the Yarn repository to the system’s repository list.

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Once the repository is added you can update the package list and proceed to install Yarn.

sudo apt update
sudo apt install yarn

The above command will install Nodejs also. If you wish to skip the Node.js installation you can use this installation command instead.

sudo apt install --no-install-recommends yarn

To check the version of the installed Yarn you can use this command.

yarn -v

Now you have successfully installed Yarn, next you can learn the simple use cases of Yarn commands.

How to use Yarn Package Manager

Here are some of the most common Yarn command you will use more often.

Create New Project Using Yarn

Creating a new project using yarn is very easy using the following command. The init script prompts you to answer some optional questions. You can ignore them or you can answer them.

yarn init project_name

Once this command is executed a package.json file will get created with the values you have provided.

Add New Dependency Using Yarn

To add a new package you your project you can add it as a dependency using the following command.

yarn add package_name

The command above will also update the package.json and yarn.lock files, so anyone working on this project when running yarn will get the same dependencies.

You can also specify the package version or package tag:

yarn add package_name@version_or_tag

Upgrade a Dependency

To upgrade the packages, you can use one of the following commands as recommended.

yarn upgrade
yarn upgrade package_name
yarn upgrade package_name@version_or_tag

If no package name is given, the command will update the project dependencies to their latest version according to the version range specified in the package.json file. Otherwise, only the specified packages are updated.

Remove a Dependency

Use the yarn remove command followed by the package name to remove a dependency.

yarn remove package_name

This command will also update the project’s package.json and yarn.lock files.

Installing All Project Dependencies

To install all project dependencies that are specified in the package.json file you can use the following command.

yarn

or

yarn install

Prepare yourself for a role working as an Information Technology Professional with Linux operating system

Conclusion

Now you have learned how to install Yarn on Ubuntu and also learned the basic commands to manage your project using Yarn package manager.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

27
751.065,85

Cart

Quantity 2.750,00
Quantity 11.444,40