How to use MOSEK in CVX?


Can we students now use Mosek freely in CVX? If so, how can I install it? I followed the guide but it could not work. It seems that they have not implemented mosek into CVX for academic use, am I right? Thanks!

(Michael C. Grant) #2

Yes, you can use MOSEK now. In order to do so, you must install it yourself, obtain an academic license, and ensure that it is properly configured to be called within MATLAB. Once you have MOSEK fully installed, you can run cvx_setup and it will detect the presence of MOSEK and use it.

Please see the MOSEK web site for details; specifically:

Once you have properly installed MOSEK, typing mosekopt on the MATLAB command line will produce an output something like this:

MOSEK Version (Build date: 2011-11-18 15:41:03)
Copyright (c) 1998-2011 MOSEK ApS, Denmark. WWW:

For help type: help mosekopt.

Once you see that, run (or re-run) cvx_setup, and CVX will detect the presence of MOSEK and configure itself to use it. You will then be able to use cvx_solver mosek to select MOSEK for your models.

We are currently working with MOSEK to arrange to include a special version of MOSEK as part of the CVX package itself. There are still a number of contractual and technical details for us to work out before we can do that, however, so in the meanwhile a separate install of MOSEK is your only option.

(Stephen Becker) #3

Additional information that might help you: when following the MOSEK installation guidelines in the section “2. Installing the software” at this mosek installation website, it will instruct you to add some environment variables. For example, for linux, it will tell you to add the variables to your ~/.bashrc file. This does not always get passed on to Matlab – you can check if it worked by restarting Matlab and running getenv('MOSEKLM_LICENSE_FILE'). If you don’t see anything, then you have to fix it. In linux, you can edit ~/ the same way you edited ~/.bashrc. Or, for any distribution, you can edit your startup.m file to run a command like setenv('MOSEKLM_LICENSE_FILE','(location to mosek.lic)' ).

Similarly, check that Mosek is in your LD_LIBRARY_PATH variable. You can set this by setenv('LD_LIBRARY_PATH', [getenv('LD_LIBRARY_PATH') ':' '(location to your mosek .so or .dll library files)' ] );

The situation with Gurobi is the same. Use the above techniques to add the environment variable GUROBI_HOME, and also add the Gurobi library locations to LD_LIBRARY_PATH.


something else I missed in the documentation:
to get the mosekopt to work inside Matlab, you must also add the toolbox folder in mosek/ to your Matlab

(Michael C. Grant) #5

Yes, that’s correct. The bottom line is that MOSEK must already be working in Matlab when cvx_setup is run, or CVX will not be able to detect it.


Thanks for these information.
I typed the command: mosekopt, and it produced this output

MOSEK Version (Build date: 2012-10-26 09:00:23) Copyright (c)
1998-2012 MOSEK ApS, Denmark. WWW:

which means that Mosek is working properly. Then I typed the command cvx_setup, and it produced ONLY this output:

 Testing the cvx distribution. If this script aborts with
an error, please report the error to the authors.
No errors! cvx has been successfully installed.
NOTE: The MATLAB path has been updated to point to the cvx distribution.
In order to use cvx regularly, you must save this new path definition.
To accomplish this, add these lines to your startup.m file:
    rmpath d:\cvx\cvx\sets
    rmpath d:\cvx\cvx\keywords
    rmpath d:\cvx\cvx\builtins
    rmpath d:\cvx\cvx\commands
    rmpath d:\cvx\cvx\functions
    rmpath d:\cvx\cvx\lib
    rmpath d:\cvx\cvx\structures
    rmpath d:\cvx\cvx
    addpath d:\cvx\cvx
    addpath d:\cvx\cvx\structures
    addpath d:\cvx\cvx\lib
    addpath d:\cvx\cvx\functions
    addpath d:\cvx\cvx\commands
    addpath d:\cvx\cvx\builtins
Consult the MATLAB documentation if necessary.

which means that CVX is working properly.

However, when I type the command cvx_solver mosek, the following error message appears:

Error using cvx_solver (line 34)
Unknown, unusable, or missing solver: mosek

What Does that mean?
I don’t have a professional licence. Is this the source of the problem?
Thanks in advance.

(Michael C. Grant) #7

Please edit this post with the full output of cvx_setup, not just the last few lines.


You should probably update to MOSEK 7…

(Michael C. Grant) #9

The “bundled” version of MOSEK that I mentioned above is coming very soon. This will greatly simplify the process of installing CVX with MOSEK support.


I installed an academic License and the problem is now solved. Thanks for your attention.


I also experience problems getting cvx_setup recognize MOSEK version 7 (although mosekopt runs fine). I get the error: 1 solver skipped:
A CVX Professional license is required.

(Michael C. Grant) #12

Do you have a professional license for CVX yet? If not, get one. If so, please file a bug report and include your license file as an attachment. Without a license the new version if CVX will not work for you either.


Mosek provides free academic license without recognizing hostname. Why CVX needs to recognize hostname?

(Erling D.Andersen) #14

I strongly recommend you use MOSEK version 7 and not the older version. It is much easier to setup and include support for SDP.

(Erling D.Andersen) #15

Using the default in installation in MOSEK version 7 no OS variables has to be set on Linux and OSX :-).


I have tried but the CVX professional license is needed if I want to use mosek solver in CVX.

(Michael C. Grant) #17

This license is free for academics.

(Kushagra Singhal) #18

I installed the cvx professional license but it does not work and still skips the solver mosek. But Gurobi is installed using this license.

(Michael C. Grant) #19

My suspicion is that your CVX license is invalid. Gurobi has a separate parallel check for academic status. What does the “status” line of the license info say when you run cvx_setup?

(Kushagra Singhal) #20

Status: invalid:hostid,user …