Last active
August 19, 2026 18:54
-
-
Save pwighton/cda5fb329f7dda0985c2333009209dca to your computer and use it in GitHub Desktop.
Install FreeSurfer 8.2.0 and all patches on an Ubuntu 24.04 machine
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 FreeSurfer 8.2.0 on Ubuntu 24.04 | |
| # | |
| # Ported from: | |
| # - https://github.com/pwighton/fs-docker/blob/master/freesurfer/Dockerfile.8.2.0 | |
| # See also: | |
| # - https://surfer.nmr.mgh.harvard.edu/fswiki/rel7downloads/rel8notes | |
| set -euo pipefail | |
| FS_VERSION="8.2.0" | |
| DEB_NAME="freesurfer_ubuntu24-${FS_VERSION}_amd64.deb" | |
| DEB_URL="https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/${FS_VERSION}/${DEB_NAME}" | |
| UPDATES_URL="https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/${FS_VERSION}/fs820_updates.sh" | |
| FREESURFER_HOME="/usr/local/freesurfer/${FS_VERSION}" | |
| SUBJECTS_DIR="$HOME/freesurfer-subjects" | |
| mkdir -p $SUBJECTS_DIR | |
| WORKDIR="$(mktemp -d)" | |
| cd "$WORKDIR" | |
| # Install pre-reqs | |
| sudo apt-get -y update | |
| sudo apt-get -y install wget findutils libgomp1 procps libxt6 libxext6 libncurses6 unzip | |
| # Install FreeSurfer | |
| # - see: https://surfer.nmr.mgh.harvard.edu/fswiki/ReleaseNotes | |
| wget --progress=bar:force:noscroll "$DEB_URL" | |
| sudo apt-get -y install ./"$DEB_NAME" | |
| # Apply point-release updates/bug fixes (same idea as fs820_updates.sh in the | |
| # Rocky Dockerfile, just with the Ubuntu FREESURFER_HOME path) | |
| wget --progress=bar:force:noscroll "$UPDATES_URL" | |
| # Note: yes/tr get SIGPIPE once fs820_updates.sh finishes reading stdin and | |
| # exits, which would trip `pipefail` above even on a successful update run. | |
| # So pipefail is disabled just for this pipeline and we check the exit status | |
| # of the actual update script (the rightmost command) instead. | |
| set +o pipefail | |
| yes y | tr -d '\n' | sudo FREESURFER_HOME="$FREESURFER_HOME" bash fs820_updates.sh | |
| updates_status=${PIPESTATUS[-1]} | |
| set -o pipefail | |
| if [ "$updates_status" -ne 0 ]; then | |
| echo "fs820_updates.sh exited with status $updates_status" >&2 | |
| exit "$updates_status" | |
| fi | |
| # Clean up | |
| cd / | |
| rm -rf "$WORKDIR" | |
| # Set up FreeSurfer environment on login | |
| { | |
| echo "" | |
| echo "# FreeSurfer ${FS_VERSION} setup (added by install_freesurfer_${FS_VERSION}.sh)" | |
| echo "export FREESURFER_HOME=\"${FREESURFER_HOME}\"" | |
| echo "export SUBJECTS_DIR=\"${SUBJECTS_DIR}\"" | |
| echo "source \"\$FREESURFER_HOME/SetUpFreeSurfer.sh\"" | |
| } >> "$HOME/.bashrc" | |
| echo "" | |
| echo "" | |
| echo "FreeSurfer ${FS_VERSION} installed to ${FREESURFER_HOME}" | |
| echo "Environment setup added to $HOME/.bashrc - run 'source $HOME/.bashrc' or open a new shell" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment