In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use Yarn on Ubuntu and other Linux distributions", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Yarn in Ubuntu and other Linux distributions" this article.
Yarn is an open source JavaScript package manager developed by Facebook. It is a replacement, or rather an improvement, for the popular npm package manager. The Facebook development team created Yarn to overcome the shortcomings of npm. Facebook claims that Yarn is faster, more reliable and more secure than npm.
Like npm, Yarn provides you with a way to automatically install, update, configure, and delete packages retrieved from the global registry.
The advantage of Yarn is that it is faster because it caches every package that has been downloaded, so you don't have to download it again. It also parallelizes operations to maximize resource utilization. Yarn also uses checksums to verify integrity before executing each installed package code. Yarn also guarantees that an installation that can run on one system will work in exactly the same way on any other system.
If you are using node.js on Ubuntu, you may already have npm installed on your system. In this case, you can use npm to install Yarn globally by:
Sudo npm install yarn-g
However, I recommend using the official way to install Yarn on Ubuntu/Debian.
Install Yarn on Ubuntu and Debian [official]
The instructions mentioned here should apply to all versions of Ubuntu, such as Ubuntu 18.04,16.04, etc. The same set of instructions applies to Debian and other Debian-based distributions.
Since this tutorial uses curl to add the GPG key for the Yarn project, it's a good idea to verify that you have installed curl.
Sudo apt install curl
If curl is not already installed, the above command will install it. Now that you have curl, you can use it to add the GPG key for the Yarn project as follows:
Curl-sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add-
After that, add the repository to the source list so that you can easily upgrade the Yarn package in the future and make the remaining system updates:
Sudo sh-c 'echo "deb https://dl.yarnpkg.com/debian/ stable main" > > / etc/apt/sources.list.d/yarn.list'
You can go on now. Update the Ubuntu or Debian system to refresh the list of available packages, and then install Yarn:
Sudo apt updatesudo apt install yarn
This will install Yarn and node.js together. After the process is complete, verify that Yarn has been successfully installed. You can do this by checking the Yarn version.
Yarn-version
To me, it shows the output like this:
Yarn-version1.12.3
This means that Yarn version 1.12.3 is installed on my system.
Use Yarn
I assume you have some basic understanding of JavaScript programming and how dependencies work. I won't give a detailed introduction here. I'll show you some basic Yarn commands that will help you get started.
Create a new project using Yarn
Like npm, Yarn can also use package.json files. Add dependencies here. All dependent packages are cached in the node_modules directory under the root of the project.
In the root directory of the project, run the following command to generate a new package.json file:
It will ask you some questions. You can press enter to skip or use the default value.
Yarn inityarn init v1.12.3question name (test_yarn): test_yarn_proectquestion version (1.0.0): 0.1question description: Test Yarnquestion entry point (index.js): question repository url:question author: abhishekquestion license (MIT): question private:success Saved package.jsonDone in 82.42s.
In this way, you get a package.json file like this:
{"name": "test_yarn_proect", "version": "0.1"," description ":" Test Yarn "," main ":" index.js "," author ":" abhishek "," license ":" MIT "}
Now that you have package.json, you can edit it manually to add or remove package dependencies, or you can use the Yarn command (preferred).
Add dependencies using Yarn
You can add dependencies to specific packages in the following ways:
Yarn add
For example, if you want to use Lodash in your project, you can add it using Yarn, as follows:
Yarn add lodashyarn add v1.12.3info No lockfile found. [1DB 4] Resolving packages... [2cap 4] Fetching packages... [3go 4] Linking dependencies... [4umb4] Building fresh packages... Success Saved lockfile.success Saved 1 new dependency.info Direct dependencies └─ [email protected] info All dependencies └─ [email protected] Done in 2.67s.
You can see that this dependency has been automatically added to the package.json file:
{"name": "test_yarn_proect", "version": "0.1"," description ":" Test Yarn "," main ":" index.js "," author ":" abhishek "," license ":" MIT "," dependencies ": {" lodash ":" ^ 4.17.11 "}}
By default, Yarn adds the latest version of the package to the dependency. If you want to use a specific version, you can specify it when you add it.
Yarn add package@version-or-tag
As usual, you can update the package.json file manually.
Use Yarn to upgrade dependencies
You can upgrade a specific dependency to its latest version using the following command:
Yarn upgrade
It will check to see if the package involved has a newer version and update it accordingly.
You can also change the version of the added dependency in the following ways:
Yarn upgrade package_name@version_or_tag
You can also use one command to upgrade all project dependencies to their latest version:
Yarn upgrade
It checks the versions of all dependencies and updates them if there are any newer versions.
Delete dependencies using Yarn
You can remove packages from project dependencies in the following ways:
Yarn remove installs all project dependencies
If you make any changes to your project.json file, you should run:
Yarn
Or
Yarn install
Install all dependencies at once.
How to remove Yarn from Ubuntu or Debian
I will complete this tutorial by introducing the steps to remove Yarn from the system if you use the above steps to install Yarn. If you realize that Yarn is no longer needed, you can delete it.
Use the following command to delete Yarn and its dependencies.
Sudo apt purge yarn
You should also delete the repository information from the source list:
Sudo rm / etc/apt/sources.list.d/yarn.list
The next step is to delete the GPG key that has been added to the trusted key. But to do this, you need to know the key. You can get it using the apt-key command:
Warning: apt-key output should not be parsed (stdout is not a terminal) pub rsa4096 2016-10-05 [SC] 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310 uid [unknown] Yarn Packaging yarn@dan.cx sub rsa4096 2016-10-05 [E] sub rsa4096 2019-01-02 [S] [expires: 2020-02-02]
The key here is the last eight characters of the GPG key fingerprint on the line that starts with pub.
So, for me, the key is 86E50310, and I will delete it using the following command:
Sudo apt-key del 86E50310
You will see OK in the output, and the GPG key of the Yarn package will be removed from the list of GPG keys trusted by the system.
That's all of the article "how to use Yarn on Ubuntu and other Linux distributions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.