0

I have created a debian package for apache-maven, so that it can be installed via apt. The problem is while exporting few environmental variables like M2_HOME and PATH etc. I have created a postinst script file and pasted the export commands into it.

After building the .deb file and making it available to my sources.list via a repository url, I am successful able to install the maven via apt. But the environmental variables are not getting exported, and so I am unable to run the mvn command.

I have understood that only variables of a child process can be sourced by a parent process. How can I source the variables of the postinst file to the entire system in the same shell session?

Braiam
  • 1
  • 11
  • 47
  • 78
Thinker-101
  • 554
  • 5
  • 19

1 Answers1

1

You can drop files in /etc/profile.d which will be sourced when users start a new (Bourne-family) shell from that point on.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Yes, that's one way. But it also means that we have to force the user to start a new shell isn't, right after apt install xxx, using a postinst echo prompt? Is there any better way to make the PATH variables available in the same session? – Thinker-101 Sep 12 '21 at 15:02
  • 1
    Nope, there is no concept of a "current session" as `dpkg` is designed to be runnable from `cron` or automated installers, too. You can print a suggestion to `source /etc/profile.d/yourpackage` at the end of the installation process. – tripleee Sep 12 '21 at 15:53