Search code examples
javalinuxmacosjboss

Cannot edit .profile on Mac OS Catalina


I wanted to declare $JAVA_HOME in .profile in /etc folder for Mac. I gave it permission using chmod 777 profile still it doesn't let me edit it.

I am new to development in mac.

Following is the error I get

enter image description here


Solution

  • Try to edit the .profile from your user, and not the one under /etc (to edit that one you need sudo rights, and even if you do edit it, most probably it won't be read correctly).

    So, as a regular user (not sudo), open the one from your user. Using open (as in your screenshot, but I would rather choose vim). One of the below commands should work:

    open ~/.profile
    

    or

    open /Users/${your-username}/.profile
    

    I guess ${your-username} is divya, so the complete path would be:

    open /Users/divya/.profile
    

    If you get an error saying The File /.../.profile does not exist, first create an empty one:

    touch ~./profile
    

    Add in the .profile file, the following line:

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
    

    (make sure to use the Java version installed on your machine)

    Then, for the changes to take place, either restart your terminal window, or type:

    source ~/.profile
    

    And to validate that you've set the $JAVA_HOME correctly:

    echo $JAVA_HOME
    

    Followed by:

    java -version