How To Install Yarn On Ubuntu 20.04 - Linuxize
Có thể bạn quan tâm
Yarn is a JavaScript package manager compatible with npm that helps you automate the process of installing, updating, configuring, and removing npm packages. It caches every download package and speeds up the installation process by parallelizing operations.
In this tutorial, we will explain how to install Yarn on Ubuntu 20.04. We will also go through the basic Yarn commands and options.
Installing Yarn on Ubuntu #
Installing Yarn on Ubuntu is fairly straightforward. We’ll enable the official Yarn repository, import the repository GPG key, and install the package. The repository is consistently maintained and provides the most up-to-date version.
Import the repository’s GPG key and add the Yarn APT repository to your system by running the following commands:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.listOnce the repository is enabled, update the package list, and install Yarn.
sudo apt updatesudo apt install yarnThe command above will also install Node.js . If you installed Node trough nvm, skip the Node.js installation with:
sudo apt install --no-install-recommends yarnOnce completed, verify the installation by printing the Yarn version:
yarn --versionThe output will look something like this:
1.22.4The version installed on your system may differ from the one shown above.
That’s it! You have successfully installed Yarn on your Ubuntu machine, and you can start using it.
Using Yarn #
Now that Yarn has been installed on your Ubuntu system, let’s explore some of the most common Yarn commands.
Creating a new project #
Start by creating a directory for your application and navigate into it:
mkdir ~/my_project && cd ~/my_projectTo create a new project, run yarn init:
yarn init my_projectThe command will ask you several questions. Enter information as prompted, or accept the defaults:
yarn init v1.22.4 question name (vagrant): 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 in 20.18s.Once completed, the script creates a basic package.json file containing the provided information. You can open and edit this file at any time.
Adding dependency #
To add an npm package to the project dependencies, use the yarn add command followed by the package name:
yarn add [package_name]The command above will update the package.json and yarn.lock files.
By default, when only the package name is given, Yarn installs the latest version. To install a specific version or tag, use the following syntax:
yarn add [package_name]@[version_or_tag]Upgrading dependency #
To upgrade the packages, use one of the following commands:
yarn upgradeyarn 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.
Removing dependency #
Use the yarn remove command followed by the package name to remove a dependency:
yarn remove [package_name]The command will remove the package and 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, run:
yarnor
yarn installConclusion #
We have shown you how to install Yarn on your Ubuntu machine. For more information about Yarn visit their documentation page.
If you have any questions or feedback, feel free to comment below.
nodejs npm yarn ubuntuTừ khóa » Cài đặt Yarn Ubuntu
-
Cách Install Yarn Trên Ubuntu 18.04 - Hướng Dẫn Từng Bước
-
Cài đặt Nvm + Node + Yarn Trên Ubuntu 18. Và 20. - Viblo
-
Yarn, Cài đặt Trình Quản Lý Phụ Thuộc JavaScript Này Cho Ubuntu 20.04
-
Cách Cài đặt Yarn Trên Ubuntu 20.04
-
Cách Cài đặt Yarn Package Manager Trên Ubuntu - Blog Tips F4vnn
-
Cách Cài đặt Yarn Trong Ubuntu 16.0.4 - VietNetwork.Vn
-
Installation | Yarn
-
Cách Cài đặt Yarn NPM Client Trên Ubuntu Và Quản Lý Sự Phụ Thuộc ...
-
Cách Cài đặt Và Cấu Hình Yarn Trên Bản Phân Phối Linux
-
Sử Dụng Yarn Trên Ubuntu Và Các Bản Phân Phối Linux Khác
-
Hướng Dẫn Install Yarn Qua Npm Hoặc Yarnpkg - Hoclaptrinh
-
Install Yarn In Ubuntu 16.0.4 | Bài Viết Tiển Nguyễn
-
Cài đặt Yarn Ubuntu 16.04 (Linux Mint 18.1) - HelpEx
-
Cài đặt Yarn Trên CentOS 8 - CLOUD VIỆT - CloudViet