Yarn, pnpm, Cargo and Homebrew
Level 4 · Other people's code
The other package managers you will meet. Yarn and pnpm in place of npm, Cargo for Rust, and Homebrew for apps on a Mac or Linux.
Course contentsLesson 9 of 13
Level 1 · The editor
Level 2 · Checking and fixing code
Level 3 · Trying code out
Level 4 · Other people's code
Level 5 · Building the project
After this lesson you can
- Say why a team picks Yarn or pnpm
- Build a Rust project with Cargo
- Install a tool with Homebrew
11 mincovers 4 glossary entries
Worth reading first: Package Managers, npm and pip
Which package manager does what
npm and pip are not the only package managers. Yarn, out since 2016, and pnpm do npm's job in their own way, and both fetch from the same npm registry. Cargo is the package manager for Rust. Homebrew, from 2009, installs whole apps and tools on macOS and Linux.
Yarn came early with ideas like a lockfile and fast installs that work offline. You add a package with yarn add, and it writes a lockfile called yarn.lock. Teams pick it for speed, and for its tools for big projects made of many parts.
pnpm saves disk space. It keeps each version of a package only once, in one store on your computer, and each project links to those files instead of copying them. Ten projects that use the same package share one copy. It is also strict: your code can only use packages it listed.
Cargo is the package manager and build tool for Rust, in one. It downloads the packages your project needs, which Rust calls crates, from crates.io. It also builds your code, runs it and tests it. The list of crates lives in a file called Cargo.toml.
Homebrew is a little different. It installs apps and command-line tools, not the parts of one project. One command, brew install and a name, fetches a tool and sets it up. Many developers use it to fill a new Mac with Git, Python and the rest in an afternoon.
Do not run Homebrew with admin rights. It is built to run as your own user, and admin rights can leave its folders owned by the wrong account. Run brew upgrade from time to time to update everything it installed at once.
The common mistake is mixing two package managers in one project. npm and Yarn each write their own lockfile. Over time the two drift apart, and teammates get different versions. Pick one, and delete the other one's lockfile.
Package managers and where they fetch from
Which one to pick
$ pnpm add react
$ cargo new hello
$ cd hello
$ cargo run
Hello, world!
$ brew install wgetWorked example
The words for this lesson4
Check yourself
Where do Yarn and pnpm get their packages from?
Finished this lesson?
Marking it complete also marks its 4 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.