0

I need to set a systemwide environment variable (i.e. NODE_ENV=production) in a FreeBSD jail.

I did try setting it in /etc/profile, but when I sourced it

root@www:/ # source /etc/profile

I got

export: Command not found.

It works on the host system.

I also tried setting it /.chsrc. But that only makes the variable availble to root but not any other users of the jail.

  • You appear to be running a shell that supports the source built-in but not export. E.g. csh. Try setenv instead. – Richard Smith Jan 14 at 11:23
0

Q: "Set a systemwide environment variable in a FreeBSD jail."

A: Set the variable both in /etc/profile and /etc/csh.cshrc.


Details

Quoting from 3.9. Shells

How to set an environment variable differs between shells. In tcsh(1) and csh(1), use setenv to set environment variables. In sh(1) and bash, use export to set the current environment variables.


All examples below were executed in a jail

FreeBSD test_01.example.org 12.0-RELEASE FreeBSD 12.0-RELEASE r341666 GENERIC  i386

Users with default shell sh and bash

/etc/profile is the right place to set global environment. For example

$ cat /etc/profile
NODE_ENV=production;    export NODE_ENV

Quoting from profile(4)

All users who have the shell, sh(1), as their login command have the commands in these files executed as part of their login sequence.

For example, the user admin

$ grep admin /etc/passwd
admin:*:1001:1001:User &:/home/admin:/bin/sh

executes /etc/profile " as part of its login sequence" and sets the environment

$ echo $NODE_ENV
production

This environment will be preserved both in csh and tcsh

$ csh
admin@test_01:~ % echo $NODE_ENV
production

It will be also preserved by su

$ su
root@test_01:/home/admin # echo $NODE_ENV
production

There is no export command in csh and tcsh. This explains the error

$ csh
admin@test_01:~ % source /etc/profile
NODE_ENV=production: Command not found.
export: Command not found.

Users with default shell csh and tcsh

/etc/csh.cshrc is the right place to set the global environment for csh and tcsh. For example

root@test_01:~ # cat /etc/csh.cshrc
setenv NODE_ENV production

Default shell of root is by default csh

root@test_01:~ # grep root /etc/passwd 
root:*:0:0:Charlie &:/root:/bin/csh

This sets the environment

root@test_01:~ # echo $NODE_ENV
production

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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