Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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
up vote 2 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 and it seems that .bashrc, .bash_profile and /etc/profile are deprecated for setting env. vars in ubuntu. – Marco Sulla 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


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.