Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I installed postgres under Lubuntu 13.04. When I try to run it:

sudo -u postgres psql

it gives me this error:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I can start it changing the port:

sudo -u postgres -i
export PGPORT=5433
psql

but I would to make it the default port. I tried to add export PGPORT=5433 to the .bashrc of postgres user, but it doesn't work; it seems that .bashrc is not executed with sudo -u, since if I do:

sudo -u postgres -i
. .bashrc
psql

it works.

Is there a way to make sudo -u USER -i execute .bashrc, or is there another way to make the change of that environment variable permanent for postgres user?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The sudoers(5) man page has a "Command Environment" section that reads, in part:

On Linux and AIX systems the contents of /etc/environment are also included.

share|improve this answer
    
Thank you all, glenn and @KunalSangwan. I' ve found also help.ubuntu.com/community/EnvironmentVariables and it seems that .bashrc, .bash_profile and /etc/profile are deprecated for setting env. vars in ubuntu. –  Lucas Malor Jun 23 '13 at 6:18

for a single user : Login to your account and open .bash_profile file $ vi ~/.bash_profile

for all user(s) : You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:

vi /etc/profile

hope that helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.