java_home environment variable in linux not found - centos

I'm trying to add java_home in linux machine (centos 5.8)
I'm adding this part to setting JAVA_HOME and PATH for all users in my machine
vi /etc/profile
export JAVA_HOME=/opt/jdkx.x.x_xx
export PATH=$PATH:$JAVA_HOME/bin
after seting it up, i try to verify it by using echo command
echo $JAVA_HOME
but it does not give me any path.Is there something wrong with my configuration?

This method will persist OS updates
echo "export JAVA_HOME=/usr/java/default/" > /etc/profile.d/java_home.sh
If you have more then on version of java install there may be trouble.

The JAVA_HOME path is different because we often install different version JDK and maybe different places. Once a I try to find the general way. There is the result.
Firstly, to query the installed jdk package name: rpm -qa|grep java
my result is:java-1.6.0-openjdk
Secondly, to query the installed place of this package
rpm -ql java-1.6.0-openjdk
Most files is under: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/
go there to confirm it is a real JDK directory
Thirdly, execute export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/ in terminal. Or add it /etc/bashrc for all user.

Question has been edited, answer doesn't make sense anymore.
Left as a placeholder for comments.
echo $SHELL will tell you which shell you are using. Most likely /bin/bash.
Assuming bash, /etc/profile is only read for a login shell (bash --login), not just a new interactive shell.
i.e. if you
sh1% vi /etc/profile
sh1% bash # /etc/profile not read
sh2% echo $JAVA_HOME
sh2%
sh1% vi /etc/profile
sh2% bash --login # /etc/profile should be read.
sh2% echo $JAVA_HOME
/opt/blah/blah/blah
sh2%

Related

I need to run a script every time I open WSL Ubuntu 18.04 on Windows 10

Every time I open WSL Ubuntu 18.04 on Windows 10 I want to run these settings automatically.
alias desktop='cd /mnt/c/Users/Dot/Desktop/ai_files'
export PYTHONPATH=${PYTHONPATH}:${HOME}/ai-safety-gridworlds
export DISPLAY=localhost:0.0
I tried making .sh script with the following content in /etc/init.d/ but it didn't work.
#!/bin/bash
alias desktop='cd /mnt/c/Users/Dot/Desktop/ai_files'
export PYTHONPATH=${PYTHONPATH}:${HOME}/ai-safety-gridworlds
export DISPLAY=localhost:0.0
To run these commands every time you open WSL, you will want to append the commands to .bashrc.
In bash, run
echo "alias desktop='cd /mnt/c/Users/Dot/Desktop/ai_files'" >> ~/.bashrc
echo "export PYTHONPATH=${PYTHONPATH}:${HOME}/ai-safety-gridworlds" >> ~/.bashrc
echo "export DISPLAY=localhost:0.0" >> ~/.bashrc
To create an environment variable which will be visible for all users on Ubuntu you can create a sh file in /etc/profile.d folder.
In example :
sudo vi /etc/profile.d/my_vars.sh && sudo chmod o+r /etc/profile.d/my_vars.sh
then include there your variables. For example:
export ORACLE_HOME="/opt/oracle/instantclient_11_2"
terminate and start wsl again. Variables should be accessible for all users.

Permanently set PGDATA environment variable Mac

To start my Postgres server I need to run these commands:
pg_ctl -D /usr/local/var/postgres start
export PGDATA='/usr/local/var/postgres'
Isn't there a way to define the PGDATA permanently and from there on only use commands like pg_ctl start to operate in the shell? Thanks.
You're half way there. The only thing you might want to do is to get PGDATA whenever you open the terminal by adding the export line to your shell config file. On my macOS machine i added the following line:
export PGDATA='/Users/john/.postgres' to ~/.bash_profile file. Don't forget to source it if you want to see the effect immediately by executing . ~/.bash_profile command. That's it from now on you can start your posters server by simply typing pg_ctl start. Hope it was worth the wait for the answer. :)
export will set the context for your current session. So we need to hack our terminal so that we will export this PGDATA env variable to every session.
If you are using zsh, you can simply execute the below command.
echo "export PGDATA='/usr/local/var/postgres'" >> ~/.zshrc
In case you are not using zsh replace ~/.zshrc in the above command with ~/.bashrc or ~/.profile
then, do source ~/.zshrc to see the immediate effect. You can instantly check using echo $PGDATA command.
Whenever you open a new terminal, your environment variable will be available by default.

I cannot add PATH to PATH file on mac

Here are my .bash_profile and .profile files:
BASH PROFILE
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
export PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH="$HOME/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"
#Virtualenvwrapper
export WORKON_HOME=$HOME/Devaus/Envs
export PROJECT_HOME=$HOME/Devaus/Envs
source /usr/local/bin/virtualenvwrapper.sh
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PROFILE
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
echo $PATH
/Users/User/Devaus/Envs/wsd/bin:/Users/User/.rvm/gems/ruby-2.1.1/bin:/Users/User/.rvm/gems/ruby- 2.1.1#global/bin:/Users/User/.rvm/rubies/ruby- 2.1.1/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/User/.rvm/bin
The question is why /Applications/Postgres.app/Contents/Versions/9.3/bin won't be added to PATH? My goal is to use psqletc commands stated in here http://postgresapp.com/documentation/cli-tools.html
Bash does not automatically read .profile if you have a .bash_profile. Usually this is set up with .bash_profile explicitly loading .profile but you don't seem to have that. Maybe add this to the beginning of your .bash_profile:
test -e ~/.profile && . ~/.profile
Or alternatively put those things in your .bash_profile instead; but then if you need some or all of these settings with /bin/sh you can't do that. It is usually a better arrangement to only have specifically Bash-only code in your .bash_profile and keep your .profile portable to classic Bourne shell (which does not allow export before a variable assignment; so you have syntax error where
export variable=value
should be
variable=value
export variable
instead for portability.)
Incidentally, you only have to export once (andPATH should already be exported by the time Bash runs your personal login files, anyway).

How to use virtualenv + virtualenvwrapper properly with Vagrant?

I found that the most convenient way of installing virtualenv + virtualenvwrapper is by using virtualenvburrito.
Now I can manage to automate my pip installs in a vagrant provision by the following:
Line in Vagrantfile:
config.vm.provision :shell, :path => "bootstrap.sh"
Lines in bootstrap.sh:
curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL
source /root/.venvburrito/startup.sh
cd /vagrant
mkvirtualenv my_project
pip install -r requirements.txt
Then I run vagrant ssh but then I have to run the following to access my virtual environment:
sudo -i
source /root/.venvburrito/startup.sh
workon my_project
I don't want to always have to run sudo -i and source /root/.venvburrito/startup.sh, I just want to be able to run workon my_project directly.
But
(I.) I can't seem to append source /root/.venvburrito/startup.sh to my ~/.profile and
(II.) even if it was appended to that file I'd get a permissionerror. I can't seem to change the permissions for any protected file either.
The best way to deal with (I.) and (II.) is to set the privileged attribute in the Vagrantfile to false.
See here

Cant access Coda application from command-line

I am having trouble accessing Coda from command-line. I installed the "command-line coda" plug-in, verified that my installation is in the correct location, yet I still can seem to access Coda. Coda sits in my "Applications" folder which is the default location for the plug-in.
Anyone have have this problem? Any tips? On the their site it is recommended that you change the path.
export CODEPATH=/Applications/Coda.app
So I included the above line in my .bash_profile which did not help.
$ Coda -v
-bash: Coda: command not found
Thanks for any direction you can provide.
The default way to open an application on a Mac is to use open -a AppName so you should be able to change your bash profile to use that:
$ open -a Coda
I've created a bash script (as opposed to using the plugin) that Gregory Tomlinson originally posted about (it looks like he's since taken it down but it looks like the following).
Create a new file in /bin called coda:
$ cd /bin
$ sudo touch coda
$ vim coda
Hit an i to enter insert mode. Then include the following code:
#! /bin/bash
if [ "$1" = "" ]; then
echo "Please specify a file to open or create"
exit 0
else
for ARG in $*
do
touch -a $ARG && open -a Coda $ARG
done
exit 0
fi
Save and quit (hit the esc to exit insert mode then type :w !sudo tee % >/dev/null followed by the return key, press L for load when prompted, then type :q to quit). Then give that file execute permissions:
$ chmod u+x coda
Start a new Terminal window and you should be able to use:
$ coda filename.foo
Or just:
$ coda
For some strange reason, my paid registered Coda 2 app just wouldn't open for me this morning. I found this terminal command that worked for me:
open -a Coda\ 2
You can also put the following in your ~/.bash_profile file:
alias coda='open -a "Coda 2"'
I had a similar problem. After installing the plug-in, I still couldn't launch coda from the command line. I took a closer look at /user/local/bin and somehow the permissions had gotten reset so I didn't have execute permissions for /user/local/bin.
I updated my permissions with:
sudo chmod o=rx,g=rx /usr/local/bin
This solved my problem. However, Coda won't launch if the specified file does not exist, which makes it hard to create a file from the command line.