Search code examples
macosmavenintellij-idea

Why do I still get Operation not permitted when running maven within intellij terminal?


I'm on macOS

From the terminal I'm able to run maven/mvn fine

letsun@letsun-mac ais% mvn --version                                               
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/letsun/Downloads/apache-maven
Java version: 1.8.0_371, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "13.2.1", arch: "x86_64", family: "mac"
letsun@letsun-mac ais% 
letsun@letsun-mac ais% sudo chmod 777  /Users/letsun/Downloads/apache-maven/bin/mvn

The chmod 777 should give system wide access to this maven file/binary

Now when I open a terminal within Intellij and try to run a mvn command, I keep getting an "Operation not permitted" error

letsun@letsun-mac ais % which mvn
/Users/letsun/Downloads/apache-maven/bin/mvn
letsun@letsun-mac ais % mvn --version
/bin/sh: /Users/letsun/Downloads/apache-maven/bin/mvn: Operation not permitted

Does anyone know what the issue is here? As you can see by running which, the Intellij terminal's mvn is pointed at the same binary as the working one.

I've tried re-starting Intellij but that hasn't solved the issue


Solution

  • maybe it's related to the macOS security feature called "System Integrity Protection" (SIP)?As I know by default, SIP prevents modifications to system files and directories, including some directories in the /usr and /bin directories. so move the apache-maven directory to a location that is not restricted by SIP, such as /usr/local
    for example like this :

    sudo mv /Users/letsun/Downloads/apache-maven /usr/local/
    

    then don't forget to update PATH

    export PATH="/usr/local/apache-maven/bin:$PATH"
    

    at the end restart IntelliJ and try running the mvn command again.
    good luck !