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.
| System | Manager | Install something |
|---|---|---|
| macOS | Homebrew | brew install php |
| Ubuntu, Debian, WSL | apt | sudo apt install php |
| Fedora, RHEL | dnf | sudo dnf install php |
| Alpine, many containers | apk | apk 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.
apt يحتاج sudo وbrew لا يحتاجه — فـHomebrew يثبّت في مجلد تملكه أنت.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
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. apt يوقع الناس: فـapt install بلا apt update حديث يثبّت من فهرس قديم، أو يعجز عن إيجاد حزمة موجودة. والأمران يُنفَّذان معًا دائمًا تقريبًا.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
PATH trick from lesson 17, applied automatically. Run the demonstration for the managers worth knowing by name.
PATH من الدرس 17 مطبَّقة تلقائيًا. شغّل العرض لمديري النسخ الجديرين بمعرفة أسمائهم.sudo, and what it really means
sudo ينفّذ أمرًا بصفة المستخدم الجذر من الدرس 1 — الحساب الذي لا قيود عليه إطلاقًا. وهو مطلوب للتثبيت على مستوى النظام ولقليل جدًا سواه. وقاعدتان: لا تنفّذ أمرًا بـsudo لأن رسالة خطأ اختفت حين فعلت، ولا تلصق أبدًا curl … | sudo bash من صفحة ويب. فذلك الأخير ينزّل نصًا لم تقرأه وينفّذه بتحكم كامل في جهازك.
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.
npm install أو composer install أو pip install — ينزّل ويشغّل شيفرة كتبها أناس لم تقابلهم قط، ومئات الحزم المنفصلة غالبًا. وهذا طبيعي ولا مفر منه، لكن يستحق أن تعرف أنه ما تفعله، ويستحق أن تفضّل مشروعًا قائمة اعتمادياته قصيرة.php --version وnode --version وgit --version. فالأنظمة تأتي بأكثر مما يتوقع الناس، والجواب يغيّر ما ينبغي أن تثبّته — وكذلك which -a من الدرس 17، فقد يريك أن ما توشك على تثبيته موجود مرتين بالفعل.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1.
Why is sudo apt update usually run before apt install?
sudo apt update عادةً قبل apt install؟update refreshes what is available; upgrade is the one that changes installed software. The two words are easy to confuse.
update يحدّث المتاح؛ وupgrade هو الذي يغيّر البرامج المثبتة. والكلمتان يسهل الخلط بينهما.2. Two projects need different versions of the same language. What solves it?
A package manager gives one system-wide version. A version manager is doing lesson 17's PATH trick for you, per directory.
3.
Why is curl … | sudo bash dangerous?
curl … | sudo bash خطر؟The pipe means nothing is saved for you to inspect, and sudo means there is nothing it may not do. Download it, read it, then run it.
sudo يعني ألا شيء ممنوع عليه. نزّله، واقرأه، ثم نفّذه.Score / النتيجة: 0 / 3
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 ما الذي يفعله لك بكلماتك