Skip to content

Instantly share code, notes, and snippets.

@felipealfonsog
Last active October 8, 2025 09:49
Show Gist options
  • Save felipealfonsog/b895967b86e4f07f3f4a182a7cbbbf4b to your computer and use it in GitHub Desktop.
Save felipealfonsog/b895967b86e4f07f3f4a182a7cbbbf4b to your computer and use it in GitHub Desktop.
Install latest version of Firefox on Linux in the menu
#!/bin/bash
# Detect the package manager
if command -v pacman &> /dev/null; then
PACKAGE_MANAGER="pacman"
INSTALL_CMD="sudo pacman -S --noconfirm"
elif command -v apt &> /dev/null; then
PACKAGE_MANAGER="apt"
INSTALL_CMD="sudo apt install -y"
elif command -v dnf &> /dev/null; then
PACKAGE_MANAGER="dnf"
INSTALL_CMD="sudo dnf install -y"
elif command -v zypper &> /dev/null; then
PACKAGE_MANAGER="zypper"
INSTALL_CMD="sudo zypper install -y"
else
echo "Unsupported package manager. Exiting..."
exit 1
fi
# Update the system
echo "Updating the system..."
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -Syu --noconfirm
else
sudo $PACKAGE_MANAGER update
sudo $PACKAGE_MANAGER upgrade -y
fi
# Install required dependencies
echo "Installing dependencies..."
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -S --noconfirm wget libx11
elif [[ "$PACKAGE_MANAGER" == "apt" ]]; then
sudo apt install -y wget libx11-xcb1
elif [[ "$PACKAGE_MANAGER" == "dnf" ]]; then
sudo dnf install -y wget libX11
elif [[ "$PACKAGE_MANAGER" == "zypper" ]]; then
sudo zypper install -y wget libX11
fi
# Check if /opt/firefox-latest exists and has the correct permissions
echo "Checking permissions for /opt/firefox-latest..."
if [ ! -d "/opt/firefox-latest" ]; then
echo "Creating directory /opt/firefox-latest..."
sudo mkdir -p /opt/firefox-latest
fi
echo "Ensuring the user has write permissions for /opt/firefox-latest..."
sudo chown -R $USER:$USER /opt/firefox-latest
sudo chmod -R u+rw /opt/firefox-latest
# Download the latest stable version of Firefox
echo "Downloading the latest stable version of Firefox..."
wget -O firefox-latest.tar.bz2 "https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US"
# Extract the downloaded file
echo "Extracting the file..."
tar -xjf firefox-latest.tar.bz2
# Remove the downloaded tarball to save space
rm firefox-latest.tar.bz2
# Remove any previous Firefox installation (optional)
echo "Removing any previous Firefox version from /opt/firefox-latest (if exists)..."
sudo rm -rf /opt/firefox-latest/*
# Move the new version to /opt/firefox-latest
echo "Installing the new version of Firefox to /opt/firefox-latest..."
sudo mv firefox/* /opt/firefox-latest/
# Create a symbolic link to run Firefox from anywhere
echo "Creating a symbolic link for Firefox..."
sudo ln -sf /opt/firefox-latest/firefox /usr/local/bin/firefox-latest
# Clean up temporary files
echo "Cleaning up temporary files..."
rm -rf firefox
# Create a .desktop file for adding Firefox to the application menu
echo "Creating a .desktop entry for Firefox in the application menu..."
cat << EOF | sudo tee /usr/share/applications/firefox-latest.desktop
[Desktop Entry]
Version=1.0
Name=Firefox Latest
Comment=The latest stable version of Firefox
Exec=/opt/firefox-latest/firefox %u
Icon=/opt/firefox-latest/browser/chrome/icons/default/default128.png
Terminal=false
Type=Application
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Firefox
EOF
# Set permissions for the .desktop file
sudo chmod +x /usr/share/applications/firefox-latest.desktop
# Final confirmation
echo "Firefox Latest has been successfully installed and added to the application menu."
# Confirmation of automatic updates for Firefox
echo "Firefox Latest should now be able to update automatically from within the browser when a new version is available."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment