博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在Ubuntu 18.04上安装Yarn
阅读量:2529 次
发布时间:2019-05-11

本文共 5282 字,大约阅读时间需要 17 分钟。

and NPM (Node Package Manager) are the two popular JavaScript package managers to automate the process of installing, updating and removing NPM packages. In this guide, we will learn how to install YARN on the Ubuntu system. We will also look into some of the commonly used YARN commands.

和NPM(节点程序包管理器)是两个流行JavaScript程序包管理器,可自动执行安装,更新和删除NPM程序包的过程。 在本指南中,我们将学习如何在Ubuntu系统上安装YARN。 我们还将研究一些常用的YARN命令。

纱线vs NPM (YARN vs NPM)

NPM has few drawbacks like network connectivity issues, slow installation process to mention few and YARN was developed by Facebook to resolve those shortcomings.

NPM几乎没有缺点,例如网络连接问题,缓慢的安装过程(很少提及),而YARN由Facebook开发来解决这些缺点。

YARN is not a replacement for NPM but in fact, it uses the same modules from NPM registry but with the different installation method. Since Yarn doesn’t require you to make any changes to the current workflow, it is possible to install YARN and use it at any point of time during your projects development phase.

YARN不能替代NPM,但实际上,它使用NPM注册表中的相同模块,但安装方法不同。 由于Yarn不需要您对当前工作流程进行任何更改,因此可以在项目开发阶段的任何时间点安装YARN并使用它。

Let’s get started with the installation of Yarn in an Ubuntu 18.04 system via the official Yarn APT package repository.

让我们开始通过正式的Yarn APT软件包存储库在Ubuntu 18.04系统中安装Yarn。

先决条件 (Prerequisites)

  • You can open a SSH session in your Ubuntu 18.04 system using root or a sudo enabled user.

    您可以使用root或启用sudo用户在Ubuntu 18.04系统中打开SSH会话。

添加纱线存储库 (Add Yarn Repository)

The first step of adding a YARN repository is to import the GPG key of the said repository using the following CURL command:

添加YARN存储库的第一步是使用以下CURL命令导入所述存储库的GPG密钥:

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

Now add the YARN repository in your Ubuntu 18.04 system by issuing the following command:

现在,通过发出以下命令,在您的Ubuntu 18.04系统中添加YARN存储库:

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

在Ubuntu上安装YARN (Installing YARN on Ubuntu)

Now that YARN repository has been added to your system, update the APT database and install YARN with the following commands:

现在已将YARN存储库添加到您的系统中,使用以下命令更新APT数据库并安装YARN:

# apt update# apt install yarn

Remember, the above command will install NodeJS along with YARN. If you have already installed NodeJS using nvm (Node Version Manager) then you can skip installation of Nodejs using the following command:

请记住,以上命令将与YARN一起安装NodeJS。 如果已经使用nvm(节点版本管理器)安装了NodeJS,则可以使用以下命令跳过Nodejs的安装:

# apt install --no-install-recommends yarn

At this point, YARN will be installed in your Ubuntu 18.04 system. Check the version of installed YARN with:

此时,YARN将安装在Ubuntu 18.04系统中。 使用以下命令检查已安装的YARN的版本:

# yarn --version
Ubuntu Yarn Version

Yarn Version

纱线版本

YARN的用途 (Usages of YARN)

1. YARN帮助 (1. YARN help)

To find the list of available commands and flags along with a brief explanation on what it does, run the following YARN command from the terminal:

要查找可用命令和标志的列表以及其功能的简要说明,请从终端运行以下YARN命令:

# yarn help
Yarn help

Yarn help

纱线帮助

Once you have successfully installed YARN, use it to create your own project, add dependencies to your project and more. Let us explore a few common usages of YARN.

成功安装YARN后,可使用它来创建自己的项目,向项目添加依赖项等等。 让我们探索YARN的一些常见用法。

2.创建一个新项目 (2. Create a New Project)

Create a new YARN project by using yarn init followed by the project name.

通过使用yarn init和项目名称创建一个新的YARN项目。

# yarn init your_yarn_project
Yarn Init

Yarn Init

纱线初始化

The above yarn command will prompt you to answer a few questions. You can answer them as per your choice or safely skip them by pressing Enter key. Once done, the yarn init command will create the package.json file containing the answers you have provided earlier. You can also manually edit the information in the package.json file at a later stage.

上面的yarn命令将提示您回答一些问题。 您可以根据自己的选择回答这些问题,也可以按Enter键安全地跳过它们。 完成后,yarn init命令将创建package.json文件,其中包含您之前提供的答案。 您也可以在稍后阶段手动编辑package.json文件中的信息。

3.添加依赖项 (3. Add dependencies)

Sometimes you need to add packages in your yarn project to fulfill the project dependencies. To do that, use the yarn add command followed by package name.

有时您需要在yarn项目中添加程序包来满足项目依赖性。 为此,请使用yarn add命令,后跟软件包名称。

# yarn add [package_name]
Yarn Add

Yarn Add

纱线添加

It is also possible to add specific version of the package with yarn add command by appending package version number or tag:

也可以通过添加软件包版本号或标签,通过yarn add命令添加特定版本的软件包:

# yarn add [package_name]@[tag_or_version]
Yarn Add Package With Specific Version

Yarn Add Package With Specific Version

纱线添加特定版本的软件包

4.删除依赖 (4. Remove dependencies)

If you want to remove an installed package, just use the yarn remove command followed by the package name.

如果要删除已安装的软件包,只需使用yarn remove命令,然后加上软件包名称即可。

# yarn remove [package_name]
Yarn Remove

Yarn Remove Package Dependencies

纱线删除包的依赖关系

5.安装所有依赖项 (5. Install all dependencies)

To install all dependencies specified in the package.json file, just use yarn or yarn install. This is useful in situation when you have manually added the dependencies in package.json file and subsequently, want to install them.

要安装package.json文件中指定的所有依赖项,只需使用yarn或yarn install。 当您在package.json文件中手动添加依赖项并随后要安装它们时,这很有用。

# yarn install      OR# yarn
Yarn Install All

Yarn Install All Packages

Yarn安装所有软件包

摘要 (Summary)

That’s it! You have now installed YARN in your Ubuntu 18.04 system and learned a few commonly used yarn command. To know more about yarn usages, visit the official of yarn.

而已! 您现在已经在Ubuntu 18.04系统中安装了YARN,并了解了一些常用的yarn命令。 要了解有关纱线用法的更多信息,请访问纱线的官方 。

翻译自:

转载地址:http://ijlzd.baihongyu.com/

你可能感兴趣的文章
flume handler
查看>>
收藏其他博客园主写的代码,学习加自用。先表示感谢!!!
查看>>
H5 表单标签
查看>>
su 与 su - 区别
查看>>
C语言编程-9_4 字符统计
查看>>
在webconfig中写好连接后,在程序中如何调用?
查看>>
限制用户不能删除SharePoint列表中的条目(项目)
查看>>
【Linux网络编程】使用GDB调试程序
查看>>
feign调用spring clound eureka 注册中心服务
查看>>
ZT:Linux上安装JDK,最准确
查看>>
LimeJS指南3
查看>>
关于C++ const成员的一些细节
查看>>
《代码大全》学习摘要(五)软件构建中的设计(下)
查看>>
C#检测驱动是否安装的问题
查看>>
web-4. 装饰页面的图像
查看>>
微信测试账户
查看>>
Android ListView上拉获取下一页
查看>>
算法练习题
查看>>
学习使用Django一 安装虚拟环境
查看>>
Hibernate视频学习笔记(8)Lazy策略
查看>>