Main Content

Change Default gcc Compiler on Linux System

MATLAB® supports only one compiler for each language on Linux® platforms. If you have multiple compilers installed, the default compiler might not be a compiler that MATLAB supports. To determine the default gcc compiler for your system, in MATLAB, type:

!which gcc

To change the default compiler, choose one of these options.

  • Change the system $PATH variable. When you change the path, this compiler becomes the default for all applications on your system.

    To change the $PATH variable, add the folder containing the compiler that MATLAB supports to the beginning of the path. Refer to your operating system documentation for the correct command to use.

  • Select a compiler that MATLAB supports when running the mex command. To change the compiler, use the varname variable set to GCC, in uppercase letters.

    For example, if the currently supported gcc compiler is version 6.3 and it is installed in the /usr/bin/gcc-6.3 folder on your system, to build timestwo.c, type:

    mex -v GCC='/usr/bin/gcc-6.3' timestwo.c


The mex -setup command does not change the default compiler on Linux.

Related Topics

External Websites