Skip to content

Instantly share code, notes, and snippets.

@SahilC
Last active March 3, 2026 07:03
Show Gist options
  • Select an option

  • Save SahilC/7ea0ec2e485139050806fe2dee8e7f26 to your computer and use it in GitHub Desktop.

Select an option

Save SahilC/7ea0ec2e485139050806fe2dee8e7f26 to your computer and use it in GitHub Desktop.
cs224r_hw2_macos.sh
#!/usr/bin/env bash
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HOME_DIR="${HOME}"
MUJOCO_DIR="${HOME_DIR}/.mujoco"
MUJOCO_VERSION="mujoco210"
OS="$(uname -s)"
append_if_missing() {
local line="$1"
local file="$2"
touch "${file}"
if ! grep -Fq "${line}" "${file}"; then
echo "${line}" >> "${file}"
fi
}
ensure_micromamba() {
if command -v micromamba >/dev/null 2>&1; then
return
fi
if [ "${OS}" = "Darwin" ]; then
if ! command -v brew >/dev/null 2>&1; then
echo "Homebrew is required on macOS before running this script."
echo "Install from https://brew.sh and re-run."
exit 1
fi
brew install micromamba
return
fi
echo "Installing micromamba..."
"${SHELL}" <(curl -Ls https://micro.mamba.pm/install.sh)
# Support both standard install locations.
if [ -x "${HOME_DIR}/.local/bin/micromamba" ]; then
export PATH="${HOME_DIR}/.local/bin:${PATH}"
elif [ -x "${HOME_DIR}/micromamba/bin/micromamba" ]; then
export PATH="${HOME_DIR}/micromamba/bin:${PATH}"
fi
if ! command -v micromamba >/dev/null 2>&1; then
echo "micromamba installation failed."
exit 1
fi
}
install_mujoco() {
mkdir -p "${MUJOCO_DIR}"
cd "${MUJOCO_DIR}"
if [ -d "${MUJOCO_DIR}/${MUJOCO_VERSION}" ]; then
echo "MuJoCo already present at ${MUJOCO_DIR}/${MUJOCO_VERSION}"
return
fi
local archive_name
if [ "${OS}" = "Darwin" ]; then
archive_name="mujoco210-macos-x86_64.tar.gz"
elif [ "${OS}" = "Linux" ]; then
archive_name="mujoco210-linux-x86_64.tar.gz"
else
echo "Unsupported OS: ${OS}"
exit 1
fi
local url="https://mujoco.org/download/${archive_name}"
echo "Downloading ${url}"
curl -L "${url}" -o "${archive_name}"
tar -xvf "${archive_name}"
}
setup_os_dependencies() {
if [ "${OS}" = "Darwin" ]; then
if ! command -v brew >/dev/null 2>&1; then
echo "Homebrew is required on macOS before running this script."
exit 1
fi
brew install wget glfw patchelf
elif [ "${OS}" = "Linux" ]; then
sudo apt-get update
sudo apt-get install -y unzip libglew-dev patchelf libegl1-mesa libgl1-mesa-glx libopengl0 wget
fi
}
setup_shell_env() {
local shell_rc
if [ "${OS}" = "Darwin" ]; then
shell_rc="${HOME_DIR}/.zshrc"
append_if_missing "export DYLD_LIBRARY_PATH=\$DYLD_LIBRARY_PATH:${MUJOCO_DIR}/${MUJOCO_VERSION}/bin" "${shell_rc}"
append_if_missing "export MUJOCO_PY_MUJOCO_PATH=${MUJOCO_DIR}/${MUJOCO_VERSION}" "${shell_rc}"
else
shell_rc="${HOME_DIR}/.bashrc"
append_if_missing "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:${MUJOCO_DIR}/${MUJOCO_VERSION}/bin" "${shell_rc}"
append_if_missing "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/lib/nvidia" "${shell_rc}"
append_if_missing "export MUJOCO_PY_MUJOCO_PATH=${MUJOCO_DIR}/${MUJOCO_VERSION}" "${shell_rc}"
fi
# Also export in this shell so the current run can proceed.
export MUJOCO_PY_MUJOCO_PATH="${MUJOCO_DIR}/${MUJOCO_VERSION}"
if [ "${OS}" = "Darwin" ]; then
export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH:-}:${MUJOCO_DIR}/${MUJOCO_VERSION}/bin"
else
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}:${MUJOCO_DIR}/${MUJOCO_VERSION}/bin:/usr/lib/nvidia"
fi
}
create_env() {
cd "${PROJECT_DIR}"
micromamba config set channel_priority flexible
if ! micromamba run -n AC python -V >/dev/null 2>&1; then
micromamba env create --file=conda_env.yml -y
else
echo "micromamba env AC already exists; skipping creation."
fi
micromamba run -n AC pip install "cython<3"
micromamba run -n AC pip install "metaworld@git+https://github.com/Farama-Foundation/Metaworld.git@a98086ababc81560772e27e7f63fe5d120c4cc50"
}
main() {
setup_os_dependencies
install_mujoco
ensure_micromamba
setup_shell_env
create_env
echo ""
echo "Setup complete."
echo "If this is your first run, open a new terminal before training to pick up shell rc changes."
echo "Activate env with: micromamba activate AC"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment