Lesson 20 / الدرس 20

Package managers and versions / مديرو الحزم والنسخ

Installing software from the terminal is one command. The harder question is which version you end up with, and what happens when a project needs a different one from the one you have.

تثبيت البرامج من الطرفية أمر واحد. والسؤال الأصعب هو أي نسخة تنتهي إليها، وماذا يحدث حين يحتاج مشروع نسخة غير التي عندك.

A package manager downloads software, puts the files where they belong, installs anything else it depends on, and records what it did so it can be removed again. That last part is what makes it different from downloading something and dragging it somewhere.

SystemManagerInstall something
macOSHomebrewbrew install php
Ubuntu, Debian, WSLaptsudo apt install php
Fedora, RHELdnfsudo dnf install php
Alpine, many containersapkapk add php

The commands differ, the ideas do not: install, remove, update the list of what is available, upgrade what you have. Note that apt needs sudo and brew does not — Homebrew installs into a directory you own.

brew install php          install
brew uninstall php        remove
brew list                 what have I installed
brew info php             what is this, and which version
brew update               refresh the catalogue
brew upgrade              update everything installed

sudo apt update           refresh the catalogue — do this FIRST on apt
sudo apt install php      install
The apt ordering catches people: apt install without a recent apt update installs from a stale catalogue, or fails to find a package that exists. The two commands are almost always run together.

When two projects need two versions

A package manager gives you one version of a thing, system-wide. That breaks down the moment one project needs PHP 8.1 and another needs 8.3. The answer is a version manager — a separate tool that keeps several versions installed and switches between them, usually per directory.

project-a/.nvmrc      ->  20.11.0
project-b/.nvmrc      ->  18.19.0

cd project-a  ->  node --version  ->  v20.11.0
cd project-b  ->  node --version  ->  v18.19.0
A small file in the project records which version it needs, and the version manager reads it. Nothing is installed or removed when you change directory — it is the PATH trick from lesson 17, applied automatically. Run the demonstration for the managers worth knowing by name.

sudo, and what it really means

The same logic applies one level up. Installing a project's dependencies — with npm install, composer install or pip install — downloads and runs code written by people you have never met, often hundreds of separate packages. It is normal and unavoidable, but it is worth knowing that it is what you are doing, and worth preferring a project whose dependency list is short.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. Why is sudo apt update usually run before apt install?

2. Two projects need different versions of the same language. What solves it?

3. Why is curl … | sudo bash dangerous?

Your task / مهمتك

Take stock of your own machine. Report which package manager you have, five things you have installed with it, and the versions of three tools you use — found with --version. Then install one small useful thing you did not have (htop, tree and jq are all good choices), show the install and the command working, and say what it does for you.

اجرد جهازك. أبلغ عن مدير الحزم الذي عندك، وخمسة أشياء ثبّتها به، ونسخ ثلاث أدوات تستخدمها — موجودة بـ--version. ثم ثبّت شيئًا صغيرًا نافعًا لم يكن عندك (htop وtree وjq كلها خيارات جيدة)، وأظهر التثبيت والأمر وهو يعمل، وقل ما الذي يفعله لك.

  • Your package manager, and five things installed with it مدير الحزم عندك، وخمسة أشياء مثبتة به
  • Three tools with their real version numbers ثلاث أدوات بأرقام نسخها الحقيقية
  • One new install, shown working تثبيت جديد واحد، معروض وهو يعمل
  • What it does for you, in your own words ما الذي يفعله لك بكلماتك
How do you want to submit? / كيف تريد التسليم؟