{"id":16615,"date":"2019-04-08T08:37:21","date_gmt":"2019-04-08T08:37:21","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=16615"},"modified":"2026-03-09T19:19:36","modified_gmt":"2026-03-09T19:19:36","slug":"how-to-install-yarn","status":"publish","type":"post","link":"\/ng\/tutorials\/how-to-install-yarn","title":{"rendered":"How to install Yarn on Ubuntu via NPM and the repository"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Yarn is a JavaScript package manager for Node.js, similar to Node Package Manager (NPM), but with improved performance and security.<\/p><p>However, unlike NPM, Yarn uses a parallel installation method to configure multiple packages simultaneously, speeding up the process. It makes the tool suitable for a complex, large project with many dependencies.<\/p><p>In this tutorial, we wil explain how to install Yarn on Ubuntu using two methods. We will also go over basic Yarn commands for dependency management so you can quickly start using the tool on your project.<\/p><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites\">Prerequisites<\/h2><p>Before installing Yarn, ensure you have a <a href=\"\/ng\/tutorials\/what-is-vps-hosting\">virtual private server<\/a> (VPS) running a newer version of Ubuntu, like <strong>22.04<\/strong> or later. Otherwise, the configuration steps might be different, and incompatibility issues might arise.<\/p><p><a href=\"\/ng\/vps-hosting\">Hostinger VPS hosting plan<\/a> supports various software, including Yarn and other JavaScript dependencies. Preparing the hosting environment is also simple since our <strong>VPS operating system control panel<\/strong> lets you install distros and applications like <a href=\"\/ng\/tutorials\/what-is-node-js\">Node.js<\/a> in one click.<\/p><p>Moreover, our VPS comes pre-installed with various features that simplify JavaScript project deployment and management. For example, you can easily ask about specific commands, request step-by-step instructions, or diagnose issues when encountering errors on your server, all using simple prompts with the <a href=\"\/blog\/vps-ai-assistant\">Kodee AI assistant<\/a>.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ng\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>After purchasing a VPS hosting plan from Hostinger and completing the onboarding process, connect to it using Terminal, an <a href=\"\/ng\/tutorials\/how-to-use-putty-ssh\">SSH client like PuTTY<\/a>, or hPanel&rsquo;s <strong>Browser terminal<\/strong>. The credentials are at the bottom of your VPS overview menu.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da9d8367c\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"1041\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/04\/vps-ssh-username-and-ip-address-on-hpanel.png\/public\" alt=\"SSH access credentials on hPanel's VPS overview page\" class=\"wp-image-125797\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/04\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/04\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/04\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/04\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/04\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>By default, you will log in as <strong>root<\/strong>. However, using this account to manage your server can be dangerous since it can run any administrative command without confirmation.<\/p><p>To minimize accidental execution, we will create a new superuser by running this command. Replace <strong>your_username<\/strong> with your desired account name:<\/p><pre class=\"wp-block-preformatted\">adduser your_username<\/pre><p>Enter the required information, like the password and contact details. Then, add the new user to the sudoers group to grant it the superuser permission:<\/p><pre class=\"wp-block-preformatted\">usermod -a -G sudo your_username<\/pre><p>Once created, switch to the new account and return to the main directory using this command:<\/p><pre class=\"wp-block-preformatted\">su your_username &amp;&amp; cd<\/pre><p>From this point, you will use more <a href=\"\/ng\/tutorials\/linux-commands\">Linux commands<\/a> to set up and manage Yarn. To help you understand the utilities, download our cheat sheet by clicking the banner below.&nbsp;<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/public\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-installing-yarn-on-ubuntu\">Installing Yarn on Ubuntu<\/h2><p>This section will cover two methods for installing Yarn on Ubuntu. Since they are suitable for different use cases, choose one based on your needs.<\/p><h3 class=\"wp-block-heading\" id=\"h-using-npm\">Using NPM<\/h3><p>The simplest way to install Yarn is to use NPM. Before doing so, <a href=\"\/ng\/tutorials\/how-to-install-nodejs-ubuntu\">configure the Node.js<\/a> JavaScript environment since the package manager requires it to run. Start by updating your local repository to get the latest software version:<\/p><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><p>Then, install Node.js and NPM using the following command:<\/p><pre class=\"wp-block-preformatted\">sudo apt install -y nodejs npm<\/pre><p>Check whether both software are installed correctly by querying their version number. To do so, enter these commands subsequently:<\/p><pre class=\"wp-block-preformatted\">nodejs --version<\/pre><pre class=\"wp-block-preformatted\">npm --version<\/pre><p>If your command-line interface returns the version number, it means the software is configured properly. Otherwise, you will see the &ldquo;Command not found error,&rdquo; which means you must rerun the installation commands.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da9d872aa\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"986\" height=\"118\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/terminal-outputs-installed-nodejs-and-npm-version.png\/public\" alt=\"Terminal outputs installed nodejs and NPM version\" class=\"wp-image-112709\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/terminal-outputs-installed-nodejs-and-npm-version.png\/w=986,fit=scale-down 986w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/terminal-outputs-installed-nodejs-and-npm-version.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/terminal-outputs-installed-nodejs-and-npm-version.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/terminal-outputs-installed-nodejs-and-npm-version.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 986px) 100vw, 986px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Now, enter this command to install Yarn. We will add the <strong>-g<\/strong> option to make the package manager available in the entire system:<\/p><pre class=\"wp-block-preformatted\">sudo npm install -g yarn<\/pre><p>Check the version of Yarn to confirm that the software is configured correctly:<\/p><pre class=\"wp-block-preformatted\">yarn --version<\/pre><h3 class=\"wp-block-heading\" id=\"h-using-the-official-yarn-repository\">Using the official Yarn repository<\/h3><p>Installing Yarn from its official repository is more complicated than using NPM. However, this method is suitable for users who want more frequent updates and direct support since the developer manages the source directly.<\/p><p>Start by adding the Yarn repository&rsquo;s GPG key to your system. This step ensures the legitimacy and integrity of your package. Here&rsquo;s the command:<\/p><pre class=\"wp-block-preformatted\">curl -sS https:\/\/dl.yarnpkg.com\/debian\/pubkey.gpg | sudo apt-key add -<\/pre><p>Now, add the Yarn repository to your local systems&rsquo; apt software library.<\/p><pre class=\"wp-block-preformatted\">echo \"deb https:\/\/dl.yarnpkg.com\/debian\/ stable main\" | sudo tee \/etc\/apt\/sources.list.d\/yarn.list<\/pre><p>Refresh the apt package manager so it can discover the new software:<\/p><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><p>Then, install yarn via apt using the following command:<\/p><pre class=\"wp-block-preformatted\">sudo apt install yarn<\/pre><p>That&rsquo;s it! Now, check the version of Yarn to confirm its installation. If you use this method, we recommend removing the repository afterward to avoid downloading or updating the software from the wrong source:<\/p><pre class=\"wp-block-preformatted\">sudo rm \/etc\/apt\/sources.list.d\/yarn.list&nbsp;<\/pre><h2 class=\"wp-block-heading\" id=\"h-basic-yarn-command-usage\">Basic Yarn command usage<\/h2><p>Now that you have installed the tool, let&rsquo;s explore several basic commands to manage Yarn dependencies.<\/p><h3 class=\"wp-block-heading\" id=\"h-updating-yarn\">Updating Yarn<\/h3><p>The command for updating Yarn differs depending on the installation method. If you use NPM, do so by running the following:<\/p><pre class=\"wp-block-preformatted\">sudo npm install -g yarn<\/pre><p>If you download Yarn from its official repository, update it using cURL like so:<\/p><pre class=\"wp-block-preformatted\">curl --compressed -o- -L https:\/\/yarnpkg.com\/install.sh | bash<\/pre><p>If you are working in a team environment, the Yarn version might differ across the developers. This situation might lead to incompatibility and workflow issues, especially if some features are missing.<\/p><p>To avoid that, force Yarn on your project to use the latest version using the following command:<\/p><pre class=\"wp-block-preformatted\">yarn policies set-version<\/pre><p>You can also set Yarn to use a specific release by entering this. Replace <strong>1.12.3<\/strong> with your preferred version number:<\/p><pre class=\"wp-block-preformatted\">yarn policies set-version 1.12.3<\/pre><h3 class=\"wp-block-heading\" id=\"h-creating-a-new-project\">Creating a New Project<\/h3><p>Before setting up a new Yarn project, create and enter a new root directory using the following command. For this tutorial, we will call it <strong>JS_project<\/strong>:<\/p><pre class=\"wp-block-preformatted\">mkdir JS_project &amp;&amp; cd JS_project<\/pre><p>Then, create the project file using this command. Replace <strong>project_name<\/strong> with the actual title:<\/p><pre class=\"wp-block-preformatted\">yarn init project_name<\/pre><p>Yarn will ask for details about the project, like the version, repository link, description, author, and licensing. Optionally, hit <strong>Enter <\/strong>to skip the question and use the default values.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da9d8a2aa\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"891\" height=\"340\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/yarn-init-questions.png\/public\" alt=\"Yarn init questions\" class=\"wp-image-112710\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/yarn-init-questions.png\/w=891,fit=scale-down 891w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/yarn-init-questions.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/yarn-init-questions.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/07\/yarn-init-questions.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>You will now see a new <strong>package.json<\/strong> file containing information about your project. Later on, you can adjust it to change the details or add new dependencies as your application develops.<\/p><h3 class=\"wp-block-heading\" id=\"h-adding-dependencies\">Adding dependencies<\/h3><p>Aside from manually editing the <strong>JSON<\/strong> file, you can add Yarn project dependencies using this command:<\/p><pre class=\"wp-block-preformatted\">yarn add package-name<\/pre><p>The command will install the specified package, add it to the <strong>package.json<\/strong> file, and update the <strong>yarn.lock <\/strong>file. You will learn about the lockfile when installing dependencies in the later section.<\/p><p>By default, the command will add the latest release of the package. However, you can install a specific version by entering:<\/p><pre class=\"wp-block-preformatted\">yarn add package-name@1.12.3<\/pre><p>You can also install a specific package by specifying its tag. For example, to install software in the stable release channel, enter:<\/p><pre class=\"wp-block-preformatted\">yarn add package-name@stable<\/pre><p>By default, Yarn will install most packages from the <a href=\"https:\/\/www.npmjs.com\/\">NPM registry<\/a>, but you can use other sources. For example, the following will set up software from a local directory:<\/p><pre class=\"wp-block-preformatted\">yarn add file:\/path\/to\/local\/folder<\/pre><p>You can also download packages directly from a Git repository by specifying the URL at the end:<\/p><pre class=\"wp-block-preformatted\">yarn add https:\/\/github.com\/user\/repo.git<\/pre><p>There are other methods of adding a Yarn dependency using the command. We recommend checking the <a href=\"https:\/\/classic.yarnpkg.com\/lang\/en\/docs\/cli\/add\/\">yarn add documentation<\/a> to learn more about them.<\/p><h3 class=\"wp-block-heading\" id=\"h-installing-all-dependencies\">Installing all dependencies<\/h3><p>You can install all dependencies specified in the <strong>package.jso<\/strong>n and <strong>yarn.lock<\/strong> files simultaneously using the following command:<\/p><pre class=\"wp-block-preformatted\">yarn install<\/pre><p>The<strong> yarn.lock<\/strong> file stores the name and version of installed dependencies, ensuring consistency when working with multiple developers. If you run the installation command, Yarn will look for the correct releases within it.<\/p><p>The <strong>yarn install <\/strong>command will download the latest package version if the lockflile doesn&rsquo;t specify a particular release. This usually happens if you manually add the dependency into the <strong>JSON<\/strong> file without updating <strong>yarn.lock<\/strong>.<\/p><p>If you wish to install packages in the <strong>JSON<\/strong> file without updating the lockfile, add the <strong>&ndash;frozen-lockfile<\/strong> argument to your command:<\/p><pre class=\"wp-block-preformatted\">yarn install --frozen-lockfile<\/pre><p>There are various other options for modifying the dependency installation behavior. To learn more about it, check the <a href=\"https:\/\/classic.yarnpkg.com\/lang\/en\/docs\/cli\/install\/\">yarn install command manual<\/a>.<\/p><h3 class=\"wp-block-heading\" id=\"h-removing-dependencies\">Removing dependencies<\/h3><p>To remove a package using Yarn, simply specify its name after the <strong>yarn remove<\/strong> command. For example, use the following to uninstall <strong>foo<\/strong>:<\/p><pre class=\"wp-block-preformatted\">yarn remove foo<\/pre><p>This command will also automatically update the information in the <strong>package.json<\/strong> and <strong>yarn.lock <\/strong>files. Since <strong>yarn remove<\/strong> uses similar parameters to <strong>yarn install<\/strong>, check the manual in the previous section to learn more about them.<\/p><p>However, you can&rsquo;t use the <strong>&ndash;frozen-lockfile<\/strong> option to block the command from modifying <strong>yarn.lock<\/strong>. This restriction ensures the lockfile gets updated to avoid accidental reinstallation.<\/p><h3 class=\"wp-block-heading\" id=\"h-running-scripts\">Running scripts<\/h3><p>You can add custom scripts within the <strong>package.json<\/strong> file to automate various tasks, like deployment or fetching data. To run them, use the following command:<\/p><pre class=\"wp-block-preformatted\">yarn run script-name<\/pre><p>Unlike dependencies, however, you must manually write the script in the <strong>JSON<\/strong> file since Yarn doesn&rsquo;t have a command for this task.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Yarn is a JavaScript package manager like NPM with improved performance and security, making it a popular choice for large projects. In Ubuntu, you can install this tool using two methods &ndash; via <strong>NPM<\/strong> or the <strong>official repository<\/strong>.<\/p><p>To download Yarn via NPM and node.js, simply run <strong>npm install -g yarn<\/strong>. If you use the official repository, add the software library to your local system using <strong>echo<\/strong> and run <strong>apt install yarn<\/strong>. Print the version to check if it is configured correctly.<\/p><p>You can rerun the installation commands to update Yarn. Meanwhile, enter <strong>yarn init <\/strong>to create a new project in your current working directory. It will create a <strong>package.json<\/strong> file in which you can specify dependencies.<\/p><p>If you want to install the dependencies listed in the <strong>JSON<\/strong> file, run the <strong>yarn install <\/strong>command. To remove a package, enter <strong>yarn remove <\/strong>followed by the software name. You can also use this tool to run custom scripts for various tasks.<\/p><h2 class=\"wp-block-heading\" id=\"h-install-yarn-on-ubuntu-faq\">Install Yarn on Ubuntu FAQ<\/h2><p>This section will answer several common questions about installing Yarn on your Ubuntu server.<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1720376278364\"><h3 class=\"schema-faq-question\">Can I install Yarn with a package manager like apt or yum?<\/h3> <p class=\"schema-faq-answer\">Yes, you can configure Yarn using your distro&rsquo;s default package manager, like <strong>apt<\/strong> or <strong>yum<\/strong>. However, the tool is not available in the local software library by default. It means you must fetch the official repository first and add them to the local one.&nbsp;<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1720376284846\"><h3 class=\"schema-faq-question\">How can I check if Yarn is already installed on my Ubuntu server?<\/h3> <p class=\"schema-faq-answer\">You can check if Yarn is installed on your Ubuntu machine by running the <strong>yarn &ndash;version <\/strong>command. If your command-line interface returns a version number, it means the tool is configured. Otherwise, it will print an error.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1720376292281\"><h3 class=\"schema-faq-question\">Which is better to use Yarn or NPM?<\/h3> <p class=\"schema-faq-answer\">Whether you should use Yarn or NPM depends on your use case. Yarn is suitable for a larger, resource-intensive project since it offers higher performance and caching. Meanwhile, NPM offers more packages and a more established community, making it more versatile.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1720376307452\"><h3 class=\"schema-faq-question\">How to uninstall Yarn on Ubuntu?<\/h3> <p class=\"schema-faq-answer\">If you install Yarn using apt, you can remove it by running <strong>sudo apt remove yarn<\/strong>. Meanwhile, enter <strong>sudo npm uninstall -g yarn <\/strong>if you configured it via the NPM package manager.&nbsp;<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yarn is a JavaScript package manager for Node.js, similar to Node Package Manager (NPM), but with improved performance and security. However, unlike NPM, Yarn uses a parallel installation method to configure multiple packages simultaneously, speeding up the process. It makes the tool suitable for a complex, large project with many dependencies. In this tutorial, we [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/how-to-install-yarn\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":145060,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Install Yarn on Ubuntu + Basic Yarn Usage","rank_math_description":"Check out this article to learn how to easily Install Yarn on an Ubuntu server via Node Package Manager (NPM) or using the official repository.","rank_math_focus_keyword":"install yarn on ubuntu","footnotes":""},"categories":[22644],"tags":[],"class_list":["post-16615","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-yarn","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/comment-installer-yarn","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-install-yarn","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-yarn","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-yarn","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-yarn","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-yarn","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-yarn","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-yarn","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-yarn","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/16615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=16615"}],"version-history":[{"count":34,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/16615\/revisions"}],"predecessor-version":[{"id":145059,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/16615\/revisions\/145059"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/145060"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=16615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=16615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=16615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}