Yarn is an ultra-fast dependency management application designed to cache the packages it downloads so they never need not be downloaded again. It is a secure and reliable program that parallelizes all operations to boost resource utilization and expedite install times. This tutorial will help you install the Yarn application on your CentOS 7 Virtual Private Server (VPS) or Dedicated Server, from the official Yarn package repository. This provides you with the most recent versions of Yarn. Ready? Let’s get started!
Before you Begin
For this installation to run smoothly you require the following:
Step 1 – Installing Yarn
To install Yarn, you must first install Node.js on your server.. For this reason, first, issue the commands below to configure the required Nodesource repository, then install Node.js:
$ sudo curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash - $ sudo yum install nodejs
Next, execute the commands below to activate the repository for Yarn and import its GPG key:
$ sudo curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo $ sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
Once you add the Yarn repository, run the command below to install Yarn:
$ sudo yum install yarn
You can now issue the following command to confirm the installation:
$ sudo yarn --version
This will give you an output showing the Yarn’s version number:
Step 2 – Using The Yarn Application
You have successfully installed Yarn and its time to learn how to use this application.
Creating A Yarn Project
Creating a Yarn project is easy using the init command. For instance, to create a project called my_project, issue the command below:
$ sudo yarn init my_project
This will give you a new script with several questions as shown below:
yarninitv1.10.1 questionname (vagrant): Linuxize questionversion (1.0.0): 0.0.1 questiondescription: TestingYarn questionentrypoint (index.js): questionrepositoryurl: questionauthor: Linuxize questionlicense (MIT): questionprivate: successSavedpackage.json Donein 20.18s.
Answer the questions accordingly or press ENTER to leave the answers to the default values. Once all the answers are given, the above script will prompt the creation of a new package.json file. This file will contain all the details provided and can be edited at any time.
Adding Dependencies in Yarn
If you find a package that is vital to any of your projects, you must incorporate it into the dependencies before you can use. The yarn add enables you to add the package with ease. The command to add a new package takes two forms: The first allows you to specify only the package’s name,
$ sudo yarn add [package_name]
Whereas the second form, can be used to add a specific version or tag for the package:
$ sudo yarn add [package_name]@[version_or_tag]
Both commands will add the stipulated package and update the files yarn.lock and package.json, that are related to that particular project.
Upgrading A Dependency
The command used to upgrade the Yarn package dependencies is almost similar to the one used to add the dependency. This command takes the form:’
$ sudo yarn upgrade [package_name]
$ sudo yarn upgrade [package_name]@[version_or_tag]
Both commands will upgrade the specified dependency to the most recent version based on the version range in your the package.json file.
Removing A Project Dependency
If you want to expunge a project dependency, simply issue the command below:
$ sudo yarn remove [package_name]
This will remove the specified dependency and update the yarn.lock and package.json files.
Implementing Project Dependencies
If you want to deploy all the available project dependencies as specified on the package.json file, then execute the command below:
$ sudo yarn
Alternatively, you can issue the command below:
$ sudo yarn install
You have successfully installed Yarn on CentOS VPS or Dedicated server. In addition, we have helped you understand the basic Yarn usage commands and it should not be difficult to get started. If you want in-depth details on how to use Yarn, go to the official Yarn documentation web page.
Check out these top 3 VPS services:
- Click this link and all your queries to best hosting will end.