I want to open Matlab without cd /usr/local/MATLAB/R2015b/bin and the sudo ./matlab.
So I sudo gedit ~/.bashrc and write the following commands in the ending:
export MATLAB_ROOT="/usr/local/MATLAB/R2015b/bin"
if [ -d "${MATLAB_ROOT}" ]; then
export PATH="${PATH}:${MATLAB_ROOT}"
fi
After source ~/.bashrc and I use echo $PATH to see that the path of matlab does exist. But when I use matlab to open the it, it will be stuck at Picked up JAVA_TOOL_OPTIONS: whereas cd /usr/local/MATLAB/R2015b/bin and the sudo ./matlab commands work well.
And if I directly use sudo ./matlab, it will show sudo:./matlab: command not found
Other information: which java shows /usr/bin/java
unset JAVA_TOOL_OPTIONS will cause another error.
Oh, I found the problem, I use the command JAVA_TOOL_OPTIONS=/usr/local/MATLAB/R2015b/bin or unset JAVA_TOOL_OPTIONS, and then get the error as follows.
It makes me recall the sudo command, so it might be a problem of permission right. Since I have to open Matlab without leaving that directory, I use ln -s /usr/local/MATLAB/R2015b/bin/matlab /path/to/your/current and then sudo ./matlab. It works.
But how to really solve this problem remains unknown. The other methods I saw like sudo apt-get remove jayatana and sudo rm /usr/share/upstart/sessions/jayatana.conf may cause unpredictable result, so I could not try them.
Related
I have script to get the java path from this command: readlink -f $(which java).
But it displays wrong path : /usr/local/bin/javavm
While I need to have this path : /usr/local/openjdk8/bin/java
I tried to give export command: export JAVA_HOME=/usr/local/openjdk8/, but the issue remains same.
I tried this post as well : https://stackoverflow.com/a/39691105/10220825
and this post : https://askubuntu.com/a/554052/905016
I also tried : sudo ln -s /usr/local/bin/javavm /usr/local/openjdk8/bin/java
but it results, ln: /usr/local/openjdk8/bin/java: File exists and issue remain same.
I dont want to hardcode it, neither I want to use other command like which java or echo $JAVA_HOME as the script is getting the expected result in Linux but only problems with FreeBSD machine.
I also dont want to apply any parsing like awk or sed from the output of readlink -f $(which java).
Can someone suggest me how to change the value from readlink -f $(which java).
What you’re seeing is the documented behaviour on FreeBSD.
If you want to select a specific Java version, set the JAVA_VERSION environment variable, e.g.:
JAVA_VERSION=8+ javac MyClass.java
If you want to find out what version is being run, set JAVAVM_DRYRUN=yes:
JAVAVM_DRYRUN=yes java
JAVAVM_DRYRUN=yes JAVA_VERSION=11 java
I'm pretty new on ubuntu, at some point in the terminal I'm running:
mortar local:illustrate pigscripts/retail-recsys.pig purchase_input -f params/retail.params
but I have this following error:
A suitable java installation could not be found. If you already have java installed
please set your JAVA_HOME environment variable before continuing. Otherwise, a
suitable java installation will need to be added to your local system.
Installing Java
On OSX run javac from the command line. This will intiate the installation. For
Linux systems please consult the documentation on your relevant package manager.
But I'm pretty sure I have Java, so please how can I set my JAVA_HOME environment variable?
First, you need to decide which installed version of Java to use? No fear, you can pick any you have -
update-java-alternatives -l
One "easy" solution is to add this to "$HOME/.bashrc",
export JAVA_HOME=$(update-java-alternatives -l | head -n 1 | awk -F ' ' '{print $NF}')
This picks the first installed JDK and takes it's JAVA_HOME (the third field) - on my system that's
/usr/lib/jvm/java-1.7.0-openjdk-amd64
export JAVA_HOME=/usr/lib/jvm/java-7-oracle
in your ~/.bashrc file.
If you want this environment variable available to all users and on system start then you can add the following to /etc/profile.d/java.sh (create it if necessary):
export JDK_HOME=/usr/lib/jvm/java-7-oracle
export JAVA_HOME=/usr/lib/jvm/java-7-oracle
Then in a terminal run:
sudo chmod +x /etc/profile.d/java.sh
source /etc/profile.d/java.sh
For JAVA_HOME to point to the active jdk, add to your ~/.bashrc
export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')
which will dynamically set the $JAVA_HOME to the JDK selected by update-alternatives.
The simplest method to set environment variable is with export:
$ export JAVA_HOME="/usr/bin"
This will temporarily set the desired variable. You can check if it was set with:
$ echo $JAVA_HOME
or
$ printenv
If you want a more permanent solution, append 'export JAVA_HOME="/usr/bin"' to .bashrc or .bash_profile file.
To check if java is properly installed:
$ which java
$ which javac
You should get similar output:
/usr/bin/java
put the line export JAVA_HOME=/usr/lib/jvm/java-xxx-oracle in your .profile file at home directory. Note that you have to replace xxx. You may need to logout and login again
In Debian/Ubuntu/Linux Mint, we could add to .bashrc
export JAVA_HOME=$(update-java-alternatives -l | head -n 1 | sed 's/\s//g')
Normally you can set paths in
~/.bashrc
with export JAVA_HOME=/usr/lib/jvm/java-version
However you may followe instructions from here for a comprehensive instruction.
By far, the ultimate guide to doing this is here. You don't need to set PATH as much as you just need to adjust the default 'java alternative' location.
you can type java in terminal,if it does not work means your did not install java.if it works, type javac in terminal.if javac dose not work,you should set the java environment variable,if it works ,there maybe something wrong with you program.
I am using Linux Mint Cinnamon 14. I have set the $JAVA_HOME and $PATH environment variables in ~/.profile as follows:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=/home/aqeel/development/jdk/jdk1.6.0_35/bin:$PATH
I then did source ~/.profile to make the proper changes.
When I execute java -version command to check the active java version, it shows the default (already installed open-jdk) java version. How can I override the default open-jdk with the one I downloaded?
UPDATE:
which java says /usr/bin/java
$JAVA_HOME/bin/java -version says 'Permission Denied'
sudo $JAVA_HOME/bin/java -version (asks for password, then) says Command not found
but cd $JAVA_HOME/bin, and ls shows that it is right directory.
While it looks like your setup is correct, there are a few things to check:
The output of env - specifically PATH.
command -v java tells you what?
Is there a java executable in $JAVA_HOME\bin and does it have the execute bit set? If not chmod a+x java it.
I trust you have source'd your .profile after adding/changing the JAVA_HOME and PATH?
Also, you can help yourself in future maintenance of your JDK installation by writing this instead:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH
Then you only need to update one env variable when you setup the JDK installation.
Finally, you may need to run hash -r to clear the Bash program cache. Other shells may need a similar command.
Cheers,
update-java-alternatives
The java executable is not found with your JAVA_HOME, it only depends on your PATH.
update-java-alternatives is a good way to manage it for the entire system is through:
update-java-alternatives -l
Sample output:
java-7-oracle 1 /usr/lib/jvm/java-7-oracle
java-8-oracle 2 /usr/lib/jvm/java-8-oracle
Choose one of the alternatives:
sudo update-java-alternatives -s java-7-oracle
Like update-alternatives, it works through symlink management. The advantage is that is manages symlinks to all the Java utilities at once: javac, java, javap, etc.
I am yet to see a JAVA_HOME effect on the JDK. So far, I have only seen it used in third-party tools, e.g. Maven.
If you want to use JDKs downloaded from Oracle's site, what worked for me (using Mint) is using update-alternatives:
I downloaded the JDK and extracted it just anywhere, for example in /home/aqeel/development/jdk/jdk1.6.0_35
I ran:
sudo update-alternatives --install /usr/bin/java java /home/aqeel/development/jdk/jdk1.6.0_35/bin/java 1
Now you can execute sudo update-alternatives --config java and choose your java version.
This doesn't set the JAVA_HOME variable, which I wanted configured, so I just added it to my ~/.bashrc, including an export JAVA_HOME="/home/aqeel/development/jdk/jdk1.6.0_35" statement
Now, I had two JDKs downloaded (let's say the second has been extracted to /home/aqeel/development/jdk/jdk-10.0.1).
How can we change the JAVA_HOME dynamically based on the current java being used?
My solution is not very elegant, I'm pretty sure there are better options out there, but anyway:
To change the JAVA_HOME dynamically based on the chosen java alternative, I added this snippet to the ~/.bashrc:
export JAVA_HOME=$(update-alternatives --query java | grep Value: | awk -F'Value: ' '{print $2}' | awk -F'/bin/java' '{print $1}')
Finally (this is out of the scope) if you have to change the java version constantly, you might want to consider:
Adding an alias to your ~./bash_aliases:
alias change-java="sudo update-alternatives --config java"
(You might have to create the file and maybe uncomment the section related to this in ~/.bashrc)
$JAVA_HOME/bin/java -version says 'Permission Denied'
If you cannot access or run code, it which be ignored if added to your path. You need to make it accessible and runnable or get a copy of your own.
Do an
ls -ld $JAVA_HOME $JAVA_HOME/bin $JAVA_HOME/bin/java
to see why you cannot access or run this program,.
When it searches for java it looks from left to right in path entries which are separated by : so you need to add the path of latest jdk/bin directory before /usr/bin, so when it searches it'll find the latest one and stop searching further.
i.e. PATH=/usr/java/jdk_1.8/bin:/usr/bin:..... and so on.
then initialize user profile using command: source ~/.bash_profile
and check with: [which java]
you'll get the right one.
check available Java versions on your Linux system by using update-alternatives command:
$ sudo update-alternatives --display java
Now that there are suitable candidates to change to, you can switch the default Java version among available Java JREs by running the following command:
$ sudo update-alternatives --config java
When prompted, select the Java version you would like to use.1 or 2 or 3 or etc..
Now you can verify the default Java version changed as follows.
$ java -version
Try this:
export JAVA_HOME=put_here_your_java_home_path
type export PATH=$JAVA_HOME/bin:$PATH (ensure that $JAVA_HOME is the first element in PATH)
try java -version
Reason: there could be other PATH elements point to alternative java home. If you put first your preferred JAVA_HOME, the system will use this one.
There is an easy way, just remove the symbolic link from "/usr/bin". It will work.
Updating the ~/.profile or ~/.bash_profile does not work sometimes. I just deleted JDK 6 and sourced .bash_profile.
Try running this:
sudo rm -rd jdk1.6.0_* #it may not let you delete without sudo
Then, modify/add your JAVA_HOME and PATH variables.
source ~/.bash_profile #assuming you've updated $JAVA_HOME and $PATH
In Linux Mint 18 Cinnamon be sure to check /etc/profile.d/jdk_home.sh I renamed this file to jdk_home.sh.old and now my path does not keep getting overridden and I can call java -version and see Java 9 as expected. Even though I correctly selected Java 9 in update-aternatives --config java this jdk_home.sh file kept overriding the $PATH on boot-up.
I have a bash script on a Linux box that runs a Jar file. When logged in as a regular user I don't have permission to run the script, but it prints the following log:
*INFO * Using JVM found at /opt/jdk6/bin/java
When I try to use the script with Sudo though, it gives:
*ERROR* Unable to locate java, please make sure java is installed and JAVA_HOME set
I've set JAVA_HOME to the same path above — can see it with echo $JAVA_HOME & it's also set as an option within the script. I'm happy that the script isn't the issue — it's a default CQ5 control script & I'm using it on dozens of other boxes without issue. Just unsure what I'm doing wrong above & presume it's something I'm missing re Linux set-up?
When I run the sudo command, does it have access to the JAVA_HOME that I set up as myself?
By default, sudo will cleanup the environment of the spawned commands. Pass -E to keep it:
sudo -E env
Compare to:
sudo env
"sudo -E " didn't solve the problem when JAVA_HOME was not exported. And when it was exported, "sudo " without -E works the same.
So you can add export JAVA_HOME=.../jdk<version> in your .bash_profile and .bashrc file.
In case you wondered what's the difference of .bash_profile and .bashrc, .bash_profile is executed upon login (e.g., show some diagnostic/welcome information). .bash_rc is executed when you open a new terminal (e.g., shift-ctrl-T).
In order to run some commands for both cases, you can put it in .bashrc file, and let .bash_profile source .bashrc:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
You could always just pass it to java explicitly like this:
sudo java -Djava.home=$JAVA_HOME Test
I'm trying to install ZeroMQ's Java library but I've been having problem. First error was ./configure complained about JAVA_HOME which everything seemed to be fine but I couldn't manage to solve it but I've found a particular solution in ZeroMQ's chat logs.
The suggested solution was;
JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" ./configure
However it doesn't work for me. The error message I've been receiving is
checking for jni.h in /Library/Java/Home/include... configure: error: cannot find jni.h in /Library/Java/Home/include.
I've tried JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" ./configure and JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home" ./configure as well but still no luck. I'd like to hear StackOverflowers' thoughts about how I can solve this.
Thanks.
Since I installed JDK1.7 from oracle, so I need to specify another JAVA_HOME.
# prepare java home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home
cd $JAVA_HOME
sudo ln -s include Headers
# fix jni_md.h: No such file or directory problem during `make`
sudo cp include/darwin/* include/
cd -
# do real stuff
git clone http://github.com/zeromq/jzmq
cd jzmq
./autogen.sh
JAVAC=$JAVA_HOME/bin/javac ./configure
make
sudo make install
Then do a test with: (note: the first local_lat will quit by itself after the test)
java -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:perf/ local_lat tcp://127.0.0.1:5555 30 100 &
java -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:perf/ remote_lat tcp://127.0.0.1:5555 30 100
Should got mean latency printed.
What I did for the missing jni.h on Mac OSX Snow Leopard:
cd /Library/Java/Home
sudo ln -s /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Headers/ ./include