Skip to content

Instantly share code, notes, and snippets.

@samilkorkmaz
Last active December 7, 2023 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samilkorkmaz/5c4d8a0ba1d4ac644100496364a5f580 to your computer and use it in GitHub Desktop.
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
#!/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