Created
September 10, 2026 17:03
-
-
Save andyl/48ab3ba968cf8d25c5dd823b305b794d to your computer and use it in GitHub Desktop.
Install Brave on Xubuntu / XFCE
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Install the Brave Browser | |
| # | |
| # install_brave show this help | |
| # install_brave 1.93.138 install that exact version and hold it | |
| # install_brave -w install the known-good version and hold it | |
| # install_brave -l list the versions the apt repo is offering | |
| # install_brave -u unhold and install the latest release | |
| # | |
| # This script is for installing Brave Browser on Xubuntu/XFCE. More info at | |
| # https://github.com/brave/brave-browser/issues/58542. | |
| # | |
| # Latest Brave is not a safe default -- Brave ships regressions often enough that | |
| # Xubuntu wants a version it has actually been happy with. That version is | |
| # LATEST_WORKING_VERSION below, and it is what `install_brave -w` gets you. | |
| # Bump it once a newer release proves out. | |
| # | |
| # There is no default action: a bare `install_brave` prints this help rather | |
| # than guessing which version you meant. Say -w for the known-good one, -u | |
| # for latest, or name a version outright. | |
| # | |
| # Brave's apt repo keeps every old build, so pinning to an older release is | |
| # just an apt install with an explicit version -- no .deb hunting on GitHub. | |
| # | |
| # Pinning also sets an apt-mark hold, otherwise the next `apt upgrade` quietly | |
| # puts you back on latest. Use -u to opt out of the pin and track latest. | |
| # | |
| # Downgrading is a special case: Chromium stamps the profile with the build | |
| # that last wrote it (see "Last Version" in the profile dir) and refuses to | |
| # open a profile from a newer build. The script warns and tells you how to get | |
| # past it -- it never touches the profile itself. | |
| set -e | |
| LATEST_WORKING_VERSION=1.93.138 | |
| PROFILE_DIR="$HOME/.config/BraveSoftware/Brave-Browser" | |
| ASSUME_YES="" | |
| usage() { | |
| sed -n '3,9p' "$0" | sed 's/^# \?//' | |
| echo | |
| echo " known-good version: $LATEST_WORKING_VERSION" | |
| exit "${1:-0}" | |
| } | |
| # -- Make sure the apt repo is configured. dl.brave.com/install.sh installs | |
| # -- the keyring, the sources file, and latest. | |
| ensure_repo() { | |
| if ! apt-cache policy brave-browser 2>/dev/null | grep -q brave-browser-apt-release; then | |
| echo "-- Setting up the Brave apt repository" | |
| curl -fsS https://dl.brave.com/install.sh | sh | |
| fi | |
| } | |
| installed_version() { | |
| dpkg-query -W -f='${Version}' brave-browser 2>/dev/null || true | |
| } | |
| unhold() { | |
| if apt-mark showhold | grep -qx brave-browser; then | |
| sudo apt-mark unhold brave-browser | |
| fi | |
| } | |
| # -- No arguments is a help request, not an install request. | |
| [ $# -eq 0 ] && usage | |
| case "$1" in | |
| -h|--help) usage ;; | |
| -y|--yes) ASSUME_YES=1; shift ;; | |
| esac | |
| case "$1" in | |
| -l|--list) | |
| ensure_repo | |
| sudo apt update | |
| apt-cache madison brave-browser | awk -F'|' '{print $2}' | |
| exit | |
| ;; | |
| -u|--unhold) | |
| # -- Drop the pin and take whatever the repo is offering, unheld, so | |
| # -- ordinary `apt upgrade` keeps it current from here on. | |
| echo "-- Releasing the hold on brave-browser and installing latest" | |
| ensure_repo | |
| unhold | |
| sudo apt update | |
| sudo apt install brave-browser | |
| exit | |
| ;; | |
| -w|--working) | |
| # -- The version this box is known to be happy with. | |
| VERSION="$LATEST_WORKING_VERSION" | |
| ;; | |
| -*) | |
| echo "install_brave: unknown option '$1'" >&2 | |
| usage 1 >&2 | |
| ;; | |
| "") | |
| # -- Only reachable as a bare `install_brave -y`. | |
| echo "install_brave: no version given" >&2 | |
| usage 1 >&2 | |
| ;; | |
| *) | |
| VERSION="$1" | |
| ;; | |
| esac | |
| ensure_repo | |
| sudo apt update | |
| if ! apt-cache madison brave-browser | awk -F'|' '{print $2}' | tr -d ' ' | grep -qx "$VERSION"; then | |
| echo "install_brave: version '$VERSION' is not in the apt repo." >&2 | |
| echo " run 'install_brave -l' to see what is available." >&2 | |
| exit 1 | |
| fi | |
| CURRENT="$(installed_version)" | |
| if [ "$CURRENT" = "$VERSION" ]; then | |
| echo "-- brave-browser is already at $VERSION" | |
| else | |
| # -- Warn before a downgrade: the profile guard below is the least of it, | |
| # -- a newer build may have written profile data this one cannot read. | |
| if [ -n "$CURRENT" ] && dpkg --compare-versions "$VERSION" lt "$CURRENT"; then | |
| echo "-- Downgrading brave-browser $CURRENT -> $VERSION" | |
| echo "-- Your profile was last written by a newer build. Back it up first:" | |
| echo "-- cp -a $PROFILE_DIR $PROFILE_DIR.bak-$CURRENT" | |
| if [ -z "$ASSUME_YES" ] && [ -t 0 ]; then | |
| read -r -p "-- Continue? [y/N] " reply | |
| case "$reply" in | |
| [yY]*) ;; | |
| *) echo "-- Aborted"; exit 1 ;; | |
| esac | |
| fi | |
| DOWNGRADE=1 | |
| fi | |
| echo "-- Installing brave-browser $VERSION" | |
| unhold # a standing hold would block the version change | |
| sudo apt install --allow-downgrades "brave-browser=$VERSION" | |
| fi | |
| echo "-- Holding brave-browser at $VERSION" | |
| sudo apt-mark hold brave-browser | |
| if [ -n "$DOWNGRADE" ]; then | |
| echo | |
| echo "-- Brave will refuse to open the profile stamped by the newer build." | |
| echo "-- Start it once with:" | |
| echo "-- brave-browser --allow-profile-downgrade" | |
| echo "-- If it still balks, remove the stamp and start normally:" | |
| echo "-- rm '$PROFILE_DIR/Last Version'" | |
| fi | |
| echo "-- Run 'install_brave -u' to unhold and return to latest" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment