Ubuntu – How to set default environment variables for other users

bashrcenvironment-variableslubuntusudo

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?

Best Answer

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.

Related Question