What is the difference between yarn build and yarn install?

yarn install is used to fetch and install all dependencies for your project which are defined in your package.json. You might want to do this when you add a dependency or if you freshly checked out the project on another computer. Also read the docs on yarn install.

yarn run build calls the script that you configured for the "build" command in your package.json. Note that yarn build is not a valid yarn command.

{
  "name": "my-package",
  "scripts": {
    "build": "babel src -d lib" // <-- this will be executed
  }
}

Also see the yarn run documentation


In a nutshell, yarn install is the command used to install all dependencies for a project, usually allocated in the package.json file. In most scenarios it is because you cloned a project and need its dependencies installed to run it.

On the other hand, yarn build is not a built-in command in the Yarn package manager. Looking at your question, it seems like you are running some #reactjs project, which might have defined a build command in its package.json file.

I hope this clarifies your doubt, but for a complete answer, please provide an example of what is your specific scenario.

Also be aware that when running custom scripts like build, test, deploy, etc. it is recommended tu use the yarn run [script] command as stated in the Yarn docs, in your case yarn run build.