Setting enviroment variables

So I got environment variables listed in my ~/.config/fish/config.fish

set -x JAVA_HOME $HOME/.jdk-15.0.2
set -x PATH $PATH $JAVA_HOME/bin

set -x NODEJS_HOME $HOME/.node-v14.15.4
set -x PATH $PATH $NODEJS_HOME/bin

set -x PATH $PATH $HOME/.yarn-v1.22.5/bin

set -x GOPATH $HOME/.go1.16
set -x PATH $PATH $HOME/.go1.16/bin

And on printenv they are displayed correctly

$ ~> printenv
COLORTERM=truecolor
CUDA_PATH=/opt/cuda
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DESKTOP_SESSION=gnome
DISPLAY=:1
GDMSESSION=gnome
GDM_LANG=en_US.UTF-8
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/752118bb_0db3_4daf_8cfe_f84695b4634a
GNOME_TERMINAL_SERVICE=:1.63
GOPATH=/home/fummie/.go1.16
GTK3_MODULES=xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module
HOME=/home/fummie
JAVA_HOME=/home/fummie/.jdk-15.0.2
LANG=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_TIME=en_US.UTF-8
LOGNAME=fummie
MAIL=/var/spool/mail/fummie
MOTD_SHOWN=pam
NODEJS_HOME=/home/fummie/.node-v14.15.4
PATH=/home/fummie/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/opt/cuda/bin:/opt/cuda/integration/nsight-compute:/opt/cuda/integration/nsight-systems:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/fummie/.jdk-15.0.2/bin:/home/fummie/.node-v14.15.4/bin:/home/fummie/.yarn-v1.22.5/bin:/home/fummie/.go1.16/bin
PWD=/home/fummie
SESSION_MANAGER=local/fummie-laptop:@/tmp/.ICE-unix/160620,unix/fummie-laptop:/tmp/.ICE-unix/160620
SHELL=/usr/bin/fish
SHLVL=1
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
TERM=xterm-256color
USER=fummie
USERNAME=fummie
VTE_VERSION=6203
WINDOWPATH=5
XAUTHORITY=/run/user/1000/gdm/Xauthority
XDG_CURRENT_DESKTOP=GNOME
XDG_MENU_PREFIX=gnome-
XDG_RUNTIME_DIR=/run/user/1000
XDG_SESSION_CLASS=user
XDG_SESSION_DESKTOP=gnome
XDG_SESSION_TYPE=x11

But when i’m trying to use node or java from console,

$ ~> node --version
v15.10.0
$ ~> java --version
openjdk 15.0.2 2021-01-19
OpenJDK Runtime Environment (build 15.0.2+7)
OpenJDK 64-Bit Server VM (build 15.0.2+7, mixed mode)

it is using kits installed by pamac as dependencies required by other programs.

I guess it will be kinda newbie question, but can I use specific kits which I manually installed from my terminal, and let programs use whatever dependencies was installed by pamac? Would appreciate any help.

P. S. Same thing is happening, when I’m using bash. My system info:

$ ~> inxi --admin --verbosity=7 --filter --no-host --width
System:
  Kernel: 5.4.100-1-MANJARO x86_64 bits: 64 compiler: gcc v: 10.2.1 
  parameters: BOOT_IMAGE=/boot/vmlinuz-5.4-x86_64 
  root=UUID=91aa9b1d-d526-4210-9a7a-84aee6250a0a ro 
  cryptdevice=UUID=7fc8779a-3b81-47bc-bc29-2dd7120938fd:cryptroot quiet 
  udev.log_priority=3 
  Desktop: GNOME 3.38.3 tk: GTK 3.24.26 wm: gnome-shell dm: GDM 3.38.2.1 
  Distro: Manjaro Linux 
Machine:
  Type: Laptop System: Timi product: TM1703 v: XMAKB3M0P160F serial: <filter> 
  Mobo: Timi model: TM1703 v: XMAKB3M0P160F serial: <filter> 
  UEFI [Legacy]: Insyde v: XMAKB3M0P160F date: 03/08/2019 
Battery:
  ID-1: BAT0 charge: 19.1 Wh condition: 30.7/40.1 Wh (76%) volts: 7.7/7.6 
  model: SUNWODA R13B02W type: Li-ion serial: <filter> status: Discharging 
Memory:
  RAM: total: 7.69 GiB used: 3.02 GiB (39.3%) 
  RAM Report: missing: Required program dmidecode not available 
CPU:
  Info: Quad Core model: Intel Core i7-8550U bits: 64 type: MT MCP 
  arch: Kaby Lake note: check family: 6 model-id: 8E (142) stepping: A (10) 
  microcode: E0 L2 cache: 8 MiB bogomips: 32012 
  Speed: 800 MHz min/max: 400/4000 MHz Core speeds (MHz): 1: 800 2: 800 3: 801 
  4: 800 5: 800 6: 800 7: 800 8: 800 
  Flags: 3dnowprefetch abm acpi adx aes aperfmperf apic arat arch_perfmon art 
  avx avx2 bmi1 bmi2 bts clflush clflushopt cmov constant_tsc cpuid 
  cpuid_fault cx16 cx8 de ds_cpl dtes64 dtherm dts epb ept ept_ad erms est 
  f16c flexpriority flush_l1d fma fpu fsgsbase fxsr ht hwp hwp_act_window 
  hwp_epp hwp_notify ibpb ibrs ida intel_pt invpcid invpcid_single lahf_lm lm 
  mca mce md_clear mmx monitor movbe mpx msr mtrr nonstop_tsc nopl nx pae pat 
  pbe pcid pclmulqdq pdcm pdpe1gb pebs pge pln pni popcnt pse pse36 pti pts 
  rdrand rdseed rdtscp rep_good sdbg sep smap smep ss ssbd sse sse2 sse4_1 
  sse4_2 ssse3 stibp syscall tm tm2 tpr_shadow tsc tsc_adjust 
  tsc_deadline_timer vme vmx vnmi vpid x2apic xgetbv1 xsave xsavec xsaveopt 
  xsaves xtopology xtpr 
  Vulnerabilities: Type: itlb_multihit status: KVM: Split huge pages 
  Type: l1tf 
  mitigation: PTE Inversion; VMX: conditional cache flushes, SMT vulnerable 
  Type: mds mitigation: Clear CPU buffers; SMT vulnerable 
  Type: meltdown mitigation: PTI 
  Type: spec_store_bypass 
  mitigation: Speculative Store Bypass disabled via prctl and seccomp 
  Type: spectre_v1 
  mitigation: usercopy/swapgs barriers and __user pointer sanitization 
  Type: spectre_v2 mitigation: Full generic retpoline, IBPB: conditional, 
  IBRS_FW, STIBP: conditional, RSB filling 
  Type: srbds mitigation: Microcode 
  Type: tsx_async_abort status: Not affected 
Graphics:
  Device-1: Intel UHD Graphics 620 vendor: Xiaomi driver: i915 v: kernel 
  bus ID: 00:02.0 chip ID: 8086:5917 class ID: 0300 
  Device-2: NVIDIA GP108BM [GeForce MX250] vendor: Xiaomi driver: nvidia 
  v: 460.39 alternate: nouveau,nvidia_drm bus ID: 01:00.0 chip ID: 10de:1d52 
  class ID: 0302 
  Device-3: Cheng Uei Precision Industry (Foxlink) XiaoMi USB 2.0 Webcam 
  type: USB driver: uvcvideo bus ID: 1-5:2 chip ID: 05c8:03a2 class ID: 0e02 
  Display: x11 server: X.org 1.20.10 compositor: gnome-shell driver: 
  loaded: modesetting,nvidia alternate: fbdev,intel,nouveau,nv,vesa 
  resolution: <missing: xdpyinfo> 
  Message: Unable to show advanced data. Required tool glxinfo missing. 
Audio:
  Device-1: Intel Sunrise Point-LP HD Audio vendor: Xiaomi 
  driver: snd_hda_intel v: kernel alternate: snd_soc_skl bus ID: 00:1f.3 
  chip ID: 8086:9d71 class ID: 0403 
  Sound Server: ALSA v: k5.4.100-1-MANJARO 
Network:
  Device-1: Intel Wireless 8265 / 8275 driver: iwlwifi v: kernel port: 3000 
  bus ID: 02:00.0 chip ID: 8086:24fd class ID: 0280 
  IF: wlp2s0 state: up mac: <filter> 
  IP v4: <filter> type: dynamic noprefixroute scope: global 
  broadcast: <filter> 
  IP v6: <filter> type: noprefixroute scope: link 
  WAN IP: <filter> 
Bluetooth:
  Device-1: Intel Bluetooth wireless interface type: USB driver: btusb v: 0.8 
  bus ID: 1-7:4 chip ID: 8087:0a2b class ID: e001 
  Message: Required tool hciconfig not installed. Check --recommends 
RAID:
  Message: No RAID data was found. 
Drives:
  Local Storage: total: 238.47 GiB used: 135.61 GiB (56.9%) 
  SMART Message: Required tool smartctl not installed. Check --recommends 
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Samsung model: MZVLB256HAHQ-00000 
  size: 238.47 GiB block size: physical: 512 B logical: 512 B speed: 31.6 Gb/s 
  lanes: 4 rotation: SSD serial: <filter> rev: EXD7201Q scheme: MBR 
  Message: No Optical or Floppy data was found. 
Partition:
  ID-1: / raw size: 238.47 GiB size: 233.73 GiB (98.01%) 
  used: 135.61 GiB (58.0%) fs: ext4 dev: /dev/dm-0 maj-min: 254:0 
  mapped: cryptroot label: N/A uuid: N/A 
Swap:
  Kernel: swappiness: 60 (default) cache pressure: 100 (default) 
  ID-1: swap-1 type: file size: 7.68 GiB used: 5.7 MiB (0.1%) priority: -2 
  file: /swapfile 
Unmounted:
  Message: No Unmounted partitions found. 
USB:
  Hub-1: 1-0:1 info: Full speed (or root) Hub ports: 12 rev: 2.0 
  speed: 480 Mb/s chip ID: 1d6b:0002 class ID: 0900 
  Device-1: 1-5:2 
  info: Cheng Uei Precision Industry (Foxlink) XiaoMi USB 2.0 Webcam 
  type: Video driver: uvcvideo interfaces: 2 rev: 2.0 speed: 480 Mb/s 
  chip ID: 05c8:03a2 class ID: 0e02 
  Device-2: 1-6:3 info: Elan Micro ELAN:Fingerprint type: <vendor specific> 
  driver: N/A interfaces: 1 rev: 2.0 speed: 12 Mb/s chip ID: 04f3:0c1a 
  class ID: 0000 
  Device-3: 1-7:4 info: Intel Bluetooth wireless interface type: Bluetooth 
  driver: btusb interfaces: 2 rev: 2.0 speed: 12 Mb/s chip ID: 8087:0a2b 
  class ID: e001 
  Hub-2: 2-0:1 info: Full speed (or root) Hub ports: 6 rev: 3.0 speed: 5 Gb/s 
  chip ID: 1d6b:0003 class ID: 0900 
Sensors:
  System Temperatures: cpu: 38.0 C mobo: 30.0 C 
  Fan Speeds (RPM): N/A 
Info:
  Processes: 263 Uptime: 2d 13h 46m wakeups: 35 Init: systemd v: 247 
  Compilers: gcc: 10.2.0 clang: 11.1.0 Packages: pacman: 1179 lib: 366 
  Shell: fish v: 3.1.2 running in: gnome-terminal inxi: 3.3.01

I don’t know much about fish to help, but i guess setting variables in ~/.config/fish/config.fish only applies to commands executed through fish.

Depending on what you are trying to achieve, you may need to define your variables elsewhere.
https://wiki.archlinux.org/index.php/Environment_variables

I suspect that’s why they’re called environment values. they are for the environment. The name kinds gives it away. :wink:

I think what you’re looking for is Global Environment Variables. See the Arch wiki page regarding global environment variables.

Edit:

I’m guessing you can also create a startup script to do it and start the script at bootup eith systemd, but that’s just a guess.

Edit 3:

From this page, I’m thinking those environment variables of yours should be defined in/etc/environment:

/etc/environment

This file is system wide file for creating, editing or removing any environment variables. Environment variables created in this file are accessible all throughout the system, by each and every user, both locally and remotely.

So you could define it in /etc/environment. But be careful, because it’ll be available to any user system-wide.

I suspect a better idea would be to define them in ~/.profile file:

.bash_profile

This file is user specific remote login file. Environment variables listed in this file are invoked every time the user is logged in remotely i.e. using ssh session. If this file is not present, system looks for either .bash_login or .profile files.

Sorry, I didn’t express myself clearly. By that I ment that I already defined them in ~/.bash_profile

#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc

export JAVA_HOME=$HOME/.jdk-15.0.2
export PATH=$PATH:$JAVA_HOME/bin

export NODEJS_HOME=$HOME/.node-v14.15.4
export PATH=$PATH:$NODEJS_HOME/bin

export PATH=$PATH:$HOME/.yarn-v1.22.5/bin

export GOPATH=$HOME/.go1.16
export PATH=$PATH:$HOME/.go1.16/bin

And in bash it acts similarly

fummie@fummie-laptop ~> bash
[fummie@fummie-laptop ~]$ printenv
SHELL=/usr/bin/fish
SESSION_MANAGER=local/fummie-laptop:@/tmp/.ICE-unix/197925,unix/fummie-laptop:/tmp/.ICE-unix/197925
COLORTERM=truecolor
XDG_MENU_PREFIX=gnome-
LC_ADDRESS=en_US.UTF-8
JAVA_HOME=/home/fummie/.jdk-15.0.2
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
DESKTOP_SESSION=gnome
LC_MONETARY=en_US.UTF-8
PWD=/home/fummie
XDG_SESSION_DESKTOP=gnome
LOGNAME=fummie
NODEJS_HOME=/home/fummie/.node-v14.15.4
XDG_SESSION_TYPE=x11
XAUTHORITY=/run/user/1000/gdm/Xauthority
WINDOWPATH=7
MOTD_SHOWN=pam
GDM_LANG=en_US.UTF-8
HOME=/home/fummie
USERNAME=fummie
LC_PAPER=en_US.UTF-8
LANG=en_US.UTF-8
XDG_CURRENT_DESKTOP=GNOME
VTE_VERSION=6203
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/dc3243d5_4e28_4ae0_8144_92e6eba24a08
XDG_SESSION_CLASS=user
TERM=xterm-256color
USER=fummie
CUDA_PATH=/opt/cuda
GNOME_TERMINAL_SERVICE=:1.59
DISPLAY=:1
SHLVL=2
LC_MESSAGES=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
XDG_RUNTIME_DIR=/run/user/1000
LC_TIME=en_US.UTF-8
GTK3_MODULES=xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module:xapp-gtk3-module
PATH=/home/fummie/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/opt/cuda/bin:/opt/cuda/integration/nsight-compute:/opt/cuda/integration/nsight-systems:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/fummie/.jdk-15.0.2/bin:/home/fummie/.node-v14.15.4/bin:/home/fummie/.yarn-v1.22.5/bin:/home/fummie/.go1.16/bin:/home/fummie/.jdk-15.0.2/bin:/home/fummie/.node-v14.15.4/bin:/home/fummie/.yarn-v1.22.5/bin:/home/fummie/.go1.16/bin
GDMSESSION=gnome
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
MAIL=/var/spool/mail/fummie
GOPATH=/home/fummie/.go1.16
_=/usr/bin/printenv
[fummie@fummie-laptop ~]$ node --version
v15.10.0
[fummie@fummie-laptop ~]$ java --version
openjdk 15.0.2 2021-01-19
OpenJDK Runtime Environment (build 15.0.2+7)
OpenJDK 64-Bit Server VM (build 15.0.2+7, mixed mode)

Now I tried both /etc/environment and etc/profile and nothing changed.
Note that that behavior fair only for node and java, yarn and go work as expected

fummie@fummie-laptop ~> yarn --version
1.22.5
fummie@fummie-laptop ~> go version
go version go1.16 linux/amd64

So my best guess, that node 15.10.0-1 and jre-openjdk 15.0.2.u7-1 installed by pamac somehow override node and java varuables of .node-v14.15.4 and .jdk-15.0.2, which I placed in my home folder and defined in ~/.bash_config and ~/.config/fish/config.fish manually. If it’s true, I don’t know how to prevent this or if it even possible.

None of the above is correct. Use global variables as follows: set -gx %key% %value%. So in fact, you did right initially, just use -gx instead of -x.

Btw never mess with /etc/environment. It’s kinda using a hydraulic press in order to knock a nail.
Oh yeah, and consider reading fishshell.com/doc

As for bash, it’s not the same or similar as you said, it’s just different. For bash you need to set things in .bashrc / .bash_profile - it will ignore your “settings” unless you set variables there.

PS: I’ve changed the title. Hope you don’t mind.

2 Likes

Well, it teaches you proper aim and self-control to get it done. And it works :stuck_out_tongue:

I have set all variables in as you suggested, so here my ~/.config/config.fish:

set -gx JAVA_HOME $HOME/.jdk-15.0.2
set -gx PATH $PATH $JAVA_HOME/bin

set -gx NODEJS_HOME $HOME/.node-v14.15.4
set -gx PATH $PATH $NODEJS_HOME/bin

set -gx PATH $PATH $HOME/.yarn-v1.22.5/bin

set -gx GOPATH $HOME/.go1.16
set -gx PATH $PATH $HOME/.go1.16/bin

But it still using node and jdk installed from pamac instead of defined above

Maybe the arch script archlinux-java will help.

Nope. It only sees jdk installed by pamac

$ ~> archlinux-java status
Available Java environments:
  java-15-openjdk (default)

I believe I know what might be the cause of that weird problem. Pls look through your ~/.config/fish/fish_variables. There must be a single section with paths like this:

SETUVAR fish_user_paths:/home/openm/\x2elocal/bin\x3a/usr/local/sbin\x3a/usr/local/bin\x3a/usr/bin\x3a/opt/cuda/bin\x3a/usr/lib/jvm/default/bin\x3a/usr/bin/site_perl\x3a/usr/bin/vendor_perl\x3a/usr/bin/core_perl\x3a/home/openm/\x2ecargo/bin

\x2e means “.” (a dot), \x3a means “:”. Try editing that string the way you need it to be and make sure there’s no other strings beginning with SETUVAR fish_user_paths.
And comment/remove the relevant content of config.fish as well so only fish_variables will be responsible for settings $PATH.

2 Likes

I entered printenv, found my PATH variable:

PATH=/home/fummie/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/opt/cuda/bin:/opt/cuda/integration/nsight-compute:/opt/cuda/integration/nsight-systems:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/fummie/.jdk-15.0.2/bin:/home/fummie/.node-v14.15.4/bin:/home/fummie/.yarn-v1.22.5/bin:/home/fummie/.go1.16/bin

Copy/pasted that to ~/.config/fish/fish_variables (there was no SETUVAR fish_user_paths so I created one), changed every “.” to “\x2e” and “:” to “\x3a”, like you said, and deleted ~/.config/fish/config.fish. Now my ~/.config/fish/fish_variables looks like this:

# This file contains fish universal variable definitions.
# VERSION: 3.0
SETUVAR __fish_initialized:3100
SETUVAR fish_color_autosuggestion:555\x1ebrblack
SETUVAR fish_color_cancel:\x2dr
SETUVAR fish_color_command:005fd7
SETUVAR fish_color_comment:990000
SETUVAR fish_color_cwd:green
SETUVAR fish_color_cwd_root:red
SETUVAR fish_color_end:009900
SETUVAR fish_color_error:ff0000
SETUVAR fish_color_escape:00a6b2
SETUVAR fish_color_history_current:\x2d\x2dbold
SETUVAR fish_color_host:normal
SETUVAR fish_color_host_remote:yellow
SETUVAR fish_color_match:\x2d\x2dbackground\x3dbrblue
SETUVAR fish_color_normal:normal
SETUVAR fish_color_operator:00a6b2
SETUVAR fish_color_param:00afff
SETUVAR fish_color_quote:999900
SETUVAR fish_color_redirection:00afff
SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack
SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack
SETUVAR fish_color_status:red
SETUVAR fish_color_user:brgreen
SETUVAR fish_color_valid_path:\x2d\x2dunderline
SETUVAR fish_greeting:\x1d
SETUVAR fish_key_bindings:fish_default_key_bindings
SETUVAR fish_pager_color_completion:\x1d
SETUVAR fish_pager_color_description:B3A06D\x1eyellow
SETUVAR fish_pager_color_prefix:white\x1e\x2d\x2dbold\x1e\x2d\x2dunderline
SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan
SETUVAR fish_user_paths:/home/fummie/\x2elocal/bin\x3a/usr/local/bin\x3a/usr/local/sbin\x3a/usr/bin\x3a/opt/cuda/bin\x3a/opt/cuda/integration/nsight-compute\x3a/opt/cuda/integration/nsight-systems\x3a/usr/lib/jvm/default/bin\x3a/usr/bin/site_perl\x3a/usr/bin/vendor_perl\x3a/usr/bin/core_perl\x3a/home/fummie/\x2ejdk-15\x2e0\x2e2/bin\x3a/home/fummie/\x2enode-v14\x2e15\x2e4/bin\x3a/home/fummie/\x2eyarn-v1\x2e22\x2e5/bin\x3a/home/fummie/\x2ego1\x2e16/bin

And it worked!

fummie@fummie-laptop ~> node --version
v14.15.4
fummie@fummie-laptop ~> java --version
java 15.0.2 2021-01-19
Java(TM) SE Runtime Environment (build 15.0.2+7-27)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)

Many thanks!!! Now I’ll go and read fish documentation to understand what I just did :slight_smile:

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.