Last active
December 7, 2023 08:16
-
-
Save samilkorkmaz/5c4d8a0ba1d4ac644100496364a5f580 to your computer and use it in GitHub Desktop.
Download build_essential package (gcc, g++, make etc.) and all its dependencies for offline installation on Ubuntu 22.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#1.On online Ubuntu 22.04, create a folder, save this script as download_build_essential.sh | |
#2.Make script executable with chmod +x download_build_essential.sh | |
#3.Run script with ./download_build_essential.sh | |
#4.Copy downladed .deb files (~76MB) to the offline Ubuntu 22.04 | |
#5.On offline Ubuntu, run sudo dpkg -i *.deb | |
#6.Verify installation with make --version | |
# Function to download a package and its dependencies | |
download_package() { | |
package=$1 | |
# Check if the package has already been processed | |
if grep -Fxq "$package" downloaded_packages.txt | |
then | |
echo "Already downloaded: $package" | |
return | |
else | |
echo "$package" >> downloaded_packages.txt | |
fi | |
echo "Downloading $package..." | |
apt-get download $package | |
for dep in $(apt-cache depends $package | grep Depends: | sed "s/ Depends://"); do | |
# Avoid downloading virtual packages | |
if apt-cache show $dep > /dev/null 2>&1; then | |
download_package $dep | |
fi | |
done | |
} | |
# Main package to download | |
main_package="build-essential" | |
# Update package lists | |
echo "Updating package lists..." | |
sudo apt-get update | |
# Create a directory for downloads | |
download_dir=$main_package | |
mkdir -p $download_dir | |
cd $download_dir | |
# File to keep track of downloaded packages | |
touch downloaded_packages.txt | |
# Download main package and dependencies | |
download_package $main_package | |
echo "Download completed. Files saved in $download_dir." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment