<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Arshak Grigoryan</title>
    <description>The latest articles on Forem by Arshak Grigoryan (@arshak_grigoryan).</description>
    <link>https://forem.com/arshak_grigoryan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3775765%2Ffa14fb12-c33b-4d05-b02c-bd1eb01fcb2f.jpg</url>
      <title>Forem: Arshak Grigoryan</title>
      <link>https://forem.com/arshak_grigoryan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/arshak_grigoryan"/>
    <language>en</language>
    <item>
      <title>Yarn classic vs Yarn berry installation guide</title>
      <dc:creator>Arshak Grigoryan</dc:creator>
      <pubDate>Fri, 06 Mar 2026 19:04:37 +0000</pubDate>
      <link>https://forem.com/arshak_grigoryan/yarn-classic-vs-yarn-berry-installation-guide-3oob</link>
      <guid>https://forem.com/arshak_grigoryan/yarn-classic-vs-yarn-berry-installation-guide-3oob</guid>
      <description>&lt;p&gt;In this guide, we will learn how to create a new project using Yarn or how to add Yarn to an existing project.&lt;/p&gt;

&lt;p&gt;There are two variants of yarn: &lt;strong&gt;classic&lt;/strong&gt; and &lt;strong&gt;berry&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yarn classic&lt;/strong&gt; refers to version 1.x. It is currently in legacy mode and receives only bug fixes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yarn berry&lt;/strong&gt; refers to versions 2 and above. The current major version is 4.x, and it is actively maintained.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;yarn classic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1: Install yarn&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; yarn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the &lt;strong&gt;yarn classic&lt;/strong&gt; versions are available in &lt;code&gt;npm&lt;/code&gt;, we can install them via &lt;code&gt;npm&lt;/code&gt;. Note: if you have &lt;code&gt;corepack&lt;/code&gt; installed and enabled, you should disable it by running &lt;code&gt;corepack disable&lt;/code&gt; before installing &lt;code&gt;yarn&lt;/code&gt; globally.&lt;/p&gt;

&lt;p&gt;2: Initialize yarn in a new/existing project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For convenience, we add a flag &lt;code&gt;-y&lt;/code&gt; to skip the interactive form for creating new projects. This will create/update a &lt;code&gt;package.json&lt;/code&gt; file with basic fields, and now we can edit it as we want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my-yarn-classic-project"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arshak-grigoryan &amp;lt;arshak.code@gmail.com&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"MIT"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3: Set up yarn config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn config &lt;span class="nb"&gt;set&lt;/span&gt; &amp;lt;key&amp;gt; &amp;lt;value&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, this command modifies the global config. So if we want to set it on the project level, we need to create a local file &lt;code&gt;.yarnrc&lt;/code&gt; and edit it manually.&lt;/p&gt;

&lt;p&gt;4: Install dependencies&lt;/p&gt;

&lt;p&gt;For new projects, this will create a &lt;code&gt;yarn.lock&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the projects that have a &lt;code&gt;yarn.lock&lt;/code&gt; file, this command does not generate a lockfile and fails if an update is needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--frozen-lockfile&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;yarn berry&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1: Install coreapack and then enable it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; corepack
&lt;span class="nv"&gt;$ &lt;/span&gt;corepack &lt;span class="nb"&gt;enable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You probably can have an OS package manager like &lt;code&gt;homebrew&lt;/code&gt; for macOS, and Node Version Manager, like &lt;code&gt;nvm&lt;/code&gt; It is important to install &lt;code&gt;corepack&lt;/code&gt; in &lt;code&gt;npm&lt;/code&gt; global scope, and not with &lt;code&gt;homebrew&lt;/code&gt; because it will use a separate node version rather than the one you use with &lt;code&gt;nvm&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2: Install yarn&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn &lt;span class="nb"&gt;set &lt;/span&gt;version &amp;lt;version&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;set version&lt;/code&gt; supports concrete versions as well as specific tags, but it is better to install a stable version for new projects by running &lt;code&gt;yarn set version stable&lt;/code&gt;. This will set the &lt;code&gt;packageManager&lt;/code&gt; field in the &lt;code&gt;package.json&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"packageManager"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"yarn@4.12.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3: Set up yarn config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn config &lt;span class="nb"&gt;set&lt;/span&gt; &amp;lt;name&amp;gt; &amp;lt;value&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, by default, &lt;code&gt;yarn&lt;/code&gt; uses &lt;code&gt;PnP&lt;/code&gt; installation strategy, but we can change it to the traditional &lt;code&gt;node_modules&lt;/code&gt; approach.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn config &lt;span class="nb"&gt;set &lt;/span&gt;nodeLinker node_modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create/update &lt;code&gt;.yarnrc.yml&lt;/code&gt; file in the local directory, and the rule becomes a local config.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;nodeLinker&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node_modules&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4: Initialize yarn in a new project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates/updates &lt;code&gt;package.json&lt;/code&gt; file, adds other files like &lt;code&gt;yarn.lock&lt;/code&gt;, &lt;code&gt;.gitignore&lt;/code&gt;,&lt;code&gt;.gitattributes&lt;/code&gt;, and &lt;code&gt;.yarn&lt;/code&gt; directory with its files that are git-ignored&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my-yarn-berry-project"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"packageManager"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"yarn@4.12.0"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4: Add yarn to the existing project&lt;/p&gt;

&lt;p&gt;Don’t use &lt;code&gt;yarn init&lt;/code&gt; command for these purposes, as it will rewrite existing &lt;code&gt;package.json&lt;/code&gt; by removing all scripts and dependencies. Set yarn config as you want, and then install dependencies by running &lt;code&gt;yarn&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;5: Install dependencies&lt;/p&gt;

&lt;p&gt;For new projects, this will create a &lt;code&gt;yarn.lock&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the projects that have a &lt;code&gt;yarn.lock&lt;/code&gt; file, this command does not generate a lockfile and aborts with an error exit code if an update is needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--immutable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>npm</category>
      <category>yarn</category>
      <category>node</category>
    </item>
  </channel>
</rss>
