Maven only invokable from terminal while root

10,861

First need to grand ownership of the folder to myself:

sudo chmod -R 755 /usr/local/apache-maven-3.2.2/

Then I opened ~/.bash_aliases with:

sudo gedit ~/.bash_aliases

And I added:

alias mvn='/usr/local/apache-maven-3.2.2/bin/mvn

Thanks to @Ploutox for the right commands and I also did a bit of editing / corrections myself.

Share:
10,861
fIwJlxSzApHEZIl
Author by

fIwJlxSzApHEZIl

Updated on September 18, 2022

Comments

  • fIwJlxSzApHEZIl
    fIwJlxSzApHEZIl over 1 year

    I'm following the directions laid out here: http://java.dzone.com/articles/installing-maven-304-ubuntu

    Everything is in the right place and the sym link is working correctly.

    However whenever I try to call mvn from the terminal, I get:

    xyz@xyz-laptop:~/Desktop$ mvn   
    The program 'mvn' can be found in the following packages:   
     * maven   
     * maven2   
    Try: sudo apt-get install <selected package>   
    

    But if I switch to root, then it works fine:

    sudo su
    
    root@xyz-laptop:/home/xyz/Desktop# mvn  
    [INFO] Scanning for projects...   
    [INFO] ------------------------------------------------------------------------   
    [INFO] BUILD FAILURE   
    [INFO] ------------------------------------------------------------------------   
    [INFO] Total time: 0.079 s   
    [INFO] Finished at: 2014-07-30T18:11:54-07:00   
    [INFO] Final Memory: 5M/234M   
    [INFO] ------------------------------------------------------------------------   
    

    I'm very sure this is an issue with permissions but I don't know what to set the folders permissions to as I've never hit this error before. This error is frustrating me as well:

    xyz@xyz-laptop:/usr/local$ cd apache-maven-3.2.2/   
    bash: cd: apache-maven-3.2.2/: Permission denied
    
    • zargawy
      zargawy almost 10 years
      Did you install your program using sudo or su - ? Using su - will log you as root, so that may be where your problem lie. Concerning the permission, try using sudo -R 777 /usr/local/apache-maven-3.2.2/ (you might want to tweak the 777 if you are not the only user). That will allow you to access the folder as a regular user. Then, edit your ~/.bashrc and add the alias alias mvn='/usr/local/apache-maven-3.2.2/bin/mvn'
    • fIwJlxSzApHEZIl
      fIwJlxSzApHEZIl almost 10 years
      I did not use SU to install. I unpackaged the tar file and sudo cp to copy it to /usr/local. Your advice worked! Thanks! Small typo though I think you meant sudo chmod -R :D
  • kraxor
    kraxor almost 10 years
    The 777 permissions are way too permissive for this scenario. This makes every file in /usr/local/apache-maven-3.2.2/ both world writable (i.e. everyone can write them) and executable. Consider using 644 for all files and 755 for directories and files that are intended to be run.
  • Carlos Sanchez Odreman
    Carlos Sanchez Odreman about 6 years
    do you need the alias if the mvn folder is in your path?
  • fIwJlxSzApHEZIl
    fIwJlxSzApHEZIl about 6 years
    Short answer: no. I wrote this a very long time ago but I'll try to help! If you type which mvn it should output the directory of the executable that will be executed if you type in mvn. If you get nothing back you can either add mvn to your path or you can create an alias. Both might achieve similar functionality when executing in a bash terminal but have different implications. If something is on your path - that means other things can find it more easily. If something is an alias that just makes it easier for you to execute on command as needed in a terminal.