2. Which of the following is the correct syntax to install the package named curl using apt?
easy
A. apt install curl
B. apt get install curl
C. apt install -y curl
D. apt-install curl
Solution
Step 1: Identify the correct apt install syntax
The basic command is apt install package_name. Adding -y automatically confirms prompts.
Step 2: Evaluate each option
apt install curl is correct syntax but misses automatic confirmation. apt get install curl is incorrect syntax; it should be apt-get not apt get. apt-install curl uses invalid syntax. apt install -y curl is correct and includes -y for automation.
Final Answer:
apt install -y curl -> Option C
Quick Check:
Use apt install -y for automatic yes [OK]
Hint: Use -y to skip prompts during install [OK]
Common Mistakes:
Typing 'apt get' instead of 'apt-get'
Using hyphens incorrectly in command names
Forgetting sudo before apt commands
3. What will be the output of the command apt search nano if the package nano is available?
medium
A. Lists packages with 'nano' in their name or description.
B. Installs the nano package immediately.
C. Removes the nano package from the system.
D. Updates the nano package to the latest version.
Solution
Step 1: Understand the purpose of apt search
This command searches the package database for names or descriptions matching the search term.
Step 2: Analyze the command effect
It does not install, remove, or update packages; it only lists matching packages.
Final Answer:
Lists packages with 'nano' in their name or description. -> Option A
Quick Check:
apt search lists matching packages [OK]
Hint: Search shows matching packages, doesn't install or remove [OK]
Common Mistakes:
Thinking search installs packages
Confusing search with update or upgrade
Expecting no output if package is not installed
4. You run apt install git but get a permission denied error. What is the most likely fix?
medium
A. Run the command with sudo as sudo apt install git.
B. Use apt update before installing git.
C. Remove git first using apt remove git.
D. Restart the computer and try again.
Solution
Step 1: Identify cause of permission denied
Installing packages requires administrative rights, so running without sudo causes permission errors.
Step 2: Apply correct command with elevated rights
Prepend sudo to gain necessary permissions: sudo apt install git.
Final Answer:
Run the command with sudo as sudo apt install git. -> Option A
Quick Check:
Use sudo for system changes [OK]
Hint: Use sudo for install/remove commands [OK]
Common Mistakes:
Trying to install without sudo
Running update instead of fixing permissions
Restarting without fixing command permissions
5. You want to write a script that installs vim only if it is not already installed. Which command sequence correctly checks and installs using apt?
hard
A. apt search vim && sudo apt install vim
B. if ! dpkg -l | grep -q '^ii vim '; then sudo apt install -y vim; fi
C. sudo apt install vim && echo 'vim installed'
D. dpkg -s vim || apt install vim
Solution
Step 1: Understand how to check if vim is installed
Using dpkg -l lists installed packages; filtering with grep '^ii vim ' checks if vim is installed.
Step 2: Use conditional to install only if not installed
The if ! ...; then ...; fi structure runs install only if vim is missing.
Step 3: Evaluate other options
sudo apt install vim && echo 'vim installed' installs unconditionally. apt search vim && sudo apt install vim searches but does not check installation. dpkg -s vim || apt install vim misses sudo and may fail silently.
Final Answer:
if ! dpkg -l | grep -q '^ii vim '; then sudo apt install -y vim; fi -> Option B
Quick Check:
Check with dpkg, install if missing [OK]
Hint: Use dpkg -l and grep to check before install [OK]
Common Mistakes:
Installing without checking if package exists
Forgetting sudo in install command
Using apt search instead of dpkg for installed check
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.