Skip to content

Set up developer environment

Casper Jeukendrup edited this page Jul 21, 2024 · 11 revisions

Summary

  1. Running the commands in this guide
  2. Install a package manager
  3. Install CMake and Git
  4. Set up advanced developer environment (optional)
    1. All platforms
    2. Advanced Linux environment
    3. Advanced macOS environment
    4. Advanced Windows environment

Running the commands in this guide

On macOS, we support compiling on both Intel and Apple Silicon Macs. On other platforms, the supported architecture is at the moment only x86_64. Other architectures should work too, but Qt does not provide binaries for them so you'll need to compile Qt yourself or install it from a third party (e.g. your Linux distribution).

Linux and macOS

Use your terminal of choice. The built-in Terminal application is fine.

Windows

Use PowerShell to start with. Later, after you've installed Git, consider using Git Bash instead of PowerShell.

CMD (Command Prompt) will usually work but some commands require a slightly different syntax.

You probably don't want to use WSL (Windows Subsystem for Linux) or WSL2 since compiling in those environments would create Linux binaries rather than Windows executables.

Install a package manager

Having a package manager enables you to install software quickly via the command line.

Linux

Congratulations, you already have a package manager! Use the following command to find out what it is called:

which apt yum dnf pacman emerge zypper | xargs -n1 basename

macOS

Please install one of these package managers:

Windows

Please install one of these package managers:

  • Chocolatey (choco) - recommended for most users
  • Scoop (scoop) - recommended for users who lack administrator privileges (but you'll need an admin to install it for you)

If you picked Chocolatey, it is recommended that you install gsudo (sudo) to enable the choco command to be used from within non-Admin prompts:

# Once from an Administrator prompt:
choco install gsudo

# In future, from non-Admin prompts:
sudo choco install [program]  # Spawns UAC dialog to request permission

Scoop can be used from non-Admin prompts by default, but you might want to install gsudo anyway for use with other commands that require administrator privileges.

scoop install gsudo

Install CMake and Git

Use the command(s) corresponding to your package manager.

macOS

brew install cmake git
sudo port install cmake git

Windows

# Chocolatey (Admin prompt or sudo required)
choco install cmake --installargs ADD_CMAKE_TO_PATH=System
choco install git

# others
scoop install cmake git

Linux

sudo apt install cmake git
sudo dnf install cmake git
sudo pacman -S cmake git

Older distributions may not provide a recent enough version of CMake. Check near the top of MuseScore's CMakeLists.txt for the minimum required version, then run:

cmake --version

If your distribution's version of CMake is too old, try installing it via Python's package manager pip instead. Make sure you remove the distribution version first.

# Remove outdated distribution CMake
sudo apt remove --purge cmake
sudo dnf erase cmake

# Install pip for your distribution
sudo apt install python3-pip
sudo dnf install python3-pip

# Install latest CMake from pip
pip3 install wheel setuptools # need these first to install binary packages like CMake
pip3 install cmake

The CMake PyPI package (the one installed via pip) is an official method of installing CMake as documented on the CMake downloads page. However, distribution maintainers may be forced to use their distribution's CMake when building a MuseScore package, so the existence of the PyPI CMake is not a valid reason to update our minimum required version prematurely (but there may be other reasons for doing so that are valid).

Set up advanced developer environment (optional)

This section is not required to compile and run MuseScore. However, it may be required to run certain scripts in the repository that are supplementary to the build, such as scripts to generate assets, templates, translations, or other resources. It will also give you a much nicer experience on the command line!

All platforms

Some programming languages have dedicated package managers that can be used to install libraries, modules, or programs written in that language.

Programming language Package manager
Python pip or pip3
Node npm
Rust cargo
Ruby gem

Sometimes the same libraries, modules, or programs will also be available via your regular package manager (apt, choco, brew, etc.).

When installing software written in one of the above languages, you should always prefer to install it from the language-specific package manager rather than a generic package manager. Language-specific packages tend to be better supported and have a more recent version of the thing you are trying to install.

For example, when installing the Python Requests module:

# Don't do this:
sudo apt install python3-requests  # installs outdated version of Requests

# Do this instead:
sudo apt install python3-pip       # install pip
pip3 install requests              # install latest version of Requests (notice no 'sudo')

Advanced Linux environment

Congratulations, you already have an advanced developer environment!

Advanced macOS environment

For licensing reasons, macOS only provides Bash version 3 by default. Version 3 is ancient, so use these commands to install a more recent version:

brew install bash                     # Install newer Bash
which bash | sudo tee -a /etc/shells  # Allow it to run as login shell in Terminal
chsh -s "$(which bash)"               # Optional: use it as your default login shell instead of Zsh
brew install bash-completion@2        # Optional: Install Bash tab completions for common commands (e.g. Git)

For tab completion to work you must also add the following to ~/.bash_profile:

if [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]]; then
    source "/usr/local/etc/profile.d/bash_completion.sh"
fi

When writing shell scripts for macOS, it's a good idea to check the Bash version before doing anything else.

#!/usr/bin/env bash

((${BASH_VERSION%%.*} >= 5)) || { echo >&2 "$0: Error: Please upgrade Bash."; exit 1; }

# Commands from this point onwards can safely use modern Bash syntax

As well as an outdated Bash, macOS uses the BSD variants of the standard Unix tools (ls, find, grep, sed, etc.) rather than the more popular GNU variants used by Linux and most Unix-like environments on Windows (including Git Bash). Syntax and features vary slightly between the BSD and GNU variants, so bear this in mind if you need to write shell scripts that are portable across platforms.

It is possible to install the GNU variants of Unix tools on macOS, but it's probably best to avoid doing this otherwise you'll end up writing shell scripts that won't work properly without them.

Advanced Windows environment

Now that you have installed Git, you also have access to Git Bash. This is a full Bash shell plus a core set of familiar Unix tools (ls, find, grep, sed, etc.) compiled to work natively on Windows. Unless stated otherwise, Git Bash can be used instead of PowerShell and CMD for all subsequent commands in this guide.

You can access Git Bash via the Start Menu and it will launch inside MinTTY, but we recommend using it inside Windows Terminal instead. Windows Terminal is installed by default in Windows 11. Windows 10 users can install for free it from the Microsoft Store.

Launch Windows Terminal, open its Settings, and add a new profile with the following information:

  • Name: Bash
  • Starting directory: %USERPROFILE%

If you installed Git via Chocolatey or the EXE installer:

  • Command line: "%ProgramFiles%\Git\bin\bash.exe" -i
  • Icon: %ProgramFiles%\Git\mingw64\share\git\git-for-windows.ico

If you installed Git via Scoop:

  • Command line: "%UserProfile%\scoop\apps\git\current\usr\bin\bash.exe" -i
  • Icon: %UserProfile%\scoop\apps\git\current\mingw64\share\git\git-for-windows.ico

Bash will now appear in the dropdown list of profiles within Windows Terminal. You can optionally make it the default profile via Windows Terminal's Settings > Startup.

Add the following to ~/.bashrc to make the command line experience even more similar to other platforms:

# Open new Windows Terminal tabs in the same directory as the current tab.
# https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory#mingw
PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'printf "\e]9;9;%s\e\\" "`cygpath -w "$PWD" -C ANSI`"'

# Display current directory in the shell prompt and window title like on Ubuntu Linux.
PS1="\[\e]0;Bash: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "

if [[ -d "${HOME}/.local/bin" ]]; then
    export PATH="${HOME}/.local/bin:${PATH}"
fi

if [[ -d "${HOME}/bin" ]]; then
    export PATH="${HOME}/bin:${PATH}"
fi

export EDITOR="nano"  # Use Nano as the default editor for `git commit` and `git rebase -i`

# Force `ln` to create proper symlinks instead of copying files (requires permission)
export MSYS="winsymlinks:nativestrict"

# Python
export PYTHONUTF8=1 # https://peps.python.org/pep-0540/#proposal
export PYTHONIOENCODING="utf-8" # https://stackoverflow.com/a/12834315
unset PYTHONLEGACYWINDOWSFSENCODING

function killall()
{
    taskkill //F //IM "$1.exe" //T
}

# No man pages on Windows :( https://stackoverflow.com/a/77485966
function man()
(
    exec 2>&1
    for t in $(type -at "$1"); do
        case "${t}" in
        alias)
            alias "$1"
            ;;
        keyword)
            echo "$1 is a shell keyword"
            help -m "$1"  # Show Bash help.
            break
            ;;
        function)
            echo "function $(declare -f "$1")"
            ;;
        builtin)
            echo "$1 is a shell builtin"
            help -m "$1"  # Show Bash help.
            break
            ;;
        file|*)
            echo "$1 is $(which "$1")"
            command "$1" --help  # Show command's help.
            break
            ;;
        esac
        echo
    done | less
)

Hint: Use the cygpath command to convert between Windows-style (C:\) and Unix-style (/c/) file paths when you need to. Normally Git Bash does this automatically so you don't need to think about it, but sometimes you have to do it yourself, for example when using environment variables like ${LOCALAPPDATA} that were set by Windows.

Testing

Translation

Compilation

  1. Set up developer environment
  2. Install Qt and Qt Creator
  3. Get MuseScore's source code
  4. Install dependencies
  5. Compile on the command line
  6. Compile in Qt Creator

Beyond compiling

  1. Find your way around the code
  2. Submit a Pull Request
  3. Fix the CI checks

Misc. development

Architecture general

Audio

Engraving

Extensions

Google Summer of Code

References

Clone this wiki locally