How to install Yarn on CentOS 8

Yarn is a JavaScript package manager, which is compatible with npm and can help you automatically handle installation, upgrade, configuration, and removal of npm packages.

It was created to solve a series of problems with npm, such as increasing the processing speed of package installation and reducing network connection errors through parallel operations.

This guide will guide you through the installation of Yarn on CentOS 8. We will talk about how to use Yarn to create a new project, and add and remove dependencies.

1. Install Yarn on CentOS 8

Perform the following steps as root or another sudo user on CentOS 8 to install Yarn:

  1. If Node.js is not installed on your system, install the Node.js package first, enter:
sudo dnf install @nodejs

At the time of writing this article, the Node.js version in the CentOS8 software source is v10.x.

  1. Enable Yarn software source and import source GPG key:
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

The official Yarn software source has been maintained and the latest version is available.

  1. Once the software source is enabled, install Yarn:
sudo dnf install yarn
  1. Verify the installation and print the Yarn version number:
yarn --version

As of this writing, the latest version of Yarn is 1.21.1:

1.21.1

Second, use Yarn

Now that you have installed Yarn on your CentOS system, we will explore the most commonly used Yarn commands.

2.1 Create a new project###

To create a new Yarn project, use the yarn init command and add the project name. For example, to create a project named my_project, you can enter:

yarn init my_project

This script will ask you a few questions. You can answer, or press Enter to use the default value:

yarn init v1.21.1
question name(alex): Linuxize
question version(1.0.0):0.0.1
question description: Testing Yarn
question entry point(index.js):
question repository url:
question author: Linuxize
question license(MIT):
question private:
success Saved package.json
Done in20.18s.

All the commands just create a basic package.json file, which contains the information you provide. This file can be modified at any time.

You can also add Yarn in an existing code directory. To do this, switch to the directory and execute:

yarn init my_project

2.2 Add dependency###

To add a package as a dependency to your project, use the yarn add command to add the package name:

yarn add [package_name]

This command will install this package and any packages it depends on, and update the project's package.json and yarn.lock files.

By default, if only the package name is provided, Yarn will install the latest version. To install a package of a specified version or label, use the following syntax:

yarn add [package_name]@[version_or_tag]

2.3 Upgrade dependencies###

To upgrade the package, run the yarn upgrade command and add the package name:

yarn upgrade [package_name]

The above command updates all dependencies of the project to the latest version based on the content of the package.json file.

You can specify the package version or label:

yarn upgrade [package_name]@[version_or_tag]

2.4 Remove dependencies###

To remove a package from the project dependencies, run the yarn remove command and add the package name:

yarn remove [package_name]

This command also updates the package.json and yarn.lock files of the project.

2.5 Install all project dependencies###

To install all dependent packages according to the package.json file in an existing project, run:

yarn

or

yarn install

Three, summary##

We have shown you how to install yarn on a CentOS 8 machine. For more information about yarn, browse Yarn Documentation Page.

Recommended Posts

How to install Yarn on CentOS 8
How to install jdk1.8 on centOS7
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install TensorFlow on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install GCC on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
[Graphic] How to install tomcat on centos
R&D: How To Install Python 3 on CentOS 7
How to install GCC compiler on CentOS 7
How to install offline JDK1.8 on centos7.0
How to install and configure Elasticsearch on CentOS 7
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install RPM packages on CentOS Linux
How to install and configure VNC on CentOS 8
How to install and use Composer on CentOS 8
How to install and configure Redis on CentOS 8
How to install Node.js and npm on CentOS 8
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
How to install and use Curl on CentOS 8
How to install and configure Owncloud on CentOS 8
How to install VirtualBox client extension on CentOS 8
How to install Docker CE on RHEL 8 / CentOS 8
How to install and uninstall tomcat on centos
How to install and configure Redmine on CentOS 8
How to install Ruby on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04