Session Environment Variables: Difference between revisions

    From KDE UserBase Wiki
    mNo edit summary
    mNo edit summary
    (3 intermediate revisions by 3 users not shown)
    Line 5: Line 5:


    <!--T:2-->
    <!--T:2-->
    It is simple to set environment variables that affect your whole session. KDE will execute any script it finds in <tt>$HOME/.kde/env</tt> whose filename ends in <tt>.sh</tt>, and it will maintain all the environment variables set by them. It is important that any variable you want to set must be also <code>exported</code>. In the case of PATH, for instance, your system will be set up with certain likely directories as the likely places to find things. Now you are adding an extra possible search place.  You can see what is already set by opening [[Special:myLanguage/Konsole|Konsole]] and typing <code> echo $PATH</code>
    It is simple to set environment variables that affect your whole session. Plasma will execute any script it finds in <tt>$HOME/.config/plasma-workspace/env</tt> whose filename ends in <tt>.sh</tt>, and it will maintain all the environment variables set by them. It is important that any variable you want to set must be also <code>exported</code>. In the case of PATH, for instance, your system will be set up with certain likely directories as the likely places to find things. Now you are adding an extra possible search place.  You can see what is already set by opening [[Special:myLanguage/Konsole|Konsole]] and typing <code> echo $PATH</code>


    <!--T:3-->
    <!--T:3-->
    To add paths to your [http://en.wikipedia.org/wiki/Path_(computing) PATH], simply create a file named <tt>$HOME/.kde/env/path.sh</tt> with a contents similar to this:
    To add paths to your [http://en.wikipedia.org/wiki/Path_(computing) PATH], simply create a file named <tt>$HOME/.config/plasma-workspace/env/path.sh</tt> with a contents similar to this:


    <!--T:4-->
    <!--T:4-->
    Line 15: Line 15:


    <!--T:5-->
    <!--T:5-->
    Let's explore that.  The command ''export'' tells the system that this is something that should be saved and used when looking for files. Next you add the full name of the directory you want to add (in this case <tt>~/local/bin</tt>, another way of writing <tt>/home/you/local/bin</tt> - again you can use <code>echo $HOME</code> to see how that works). Finally you see the $PATH variable itself - that's because you want to add your new path into it, not replace the existing path.
    Let's explore that.  The command ''export'' tells the system that this is something that should be saved and used when looking for files. Next you add the full name of the directory you want to add (in this case <tt>$HOME/local/bin</tt>). Finally you see the $PATH variable itself - that's because you want to add your new path into it, not replace the existing path.
    {{Warning|If you want to point your home don't use '~', use $HOME instead}}


    <!--T:6-->
    <!--T:6-->
    Line 22: Line 23:
    <!--T:7-->
    <!--T:7-->
    {{Input|1=
    {{Input|1=
    source $HOME/.kde/env/path.sh
    source $HOME/.config/plasma-workspace/env/path.sh
    }}
    }}


    <!--T:8-->
    <!--T:8-->
    You can also check how KDE actually does it. It's done in your local <code>startkde</code>, which normally you can find in <tt>/usr/bin/startkde</tt>. If you are interested in reading the code, you can can view it [https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/startkde.cmake online]. Just search the file for ''environment variables''.
    You can also check how Plasma actually does it. It's done in your local <code>startkde</code>, which normally you can find in <tt>/usr/bin/startkde</tt>. If you are interested in reading the code, you can can view it [https://cgit.kde.org/plasma-workspace.git/tree/startkde/startkde.cmake online]. Just search the file for ''environment variables''.


    <!--T:9-->
    <!--T:9-->

    Revision as of 16:14, 13 June 2018

    Setting Session Environment Variables

    It is simple to set environment variables that affect your whole session. Plasma will execute any script it finds in $HOME/.config/plasma-workspace/env whose filename ends in .sh, and it will maintain all the environment variables set by them. It is important that any variable you want to set must be also exported. In the case of PATH, for instance, your system will be set up with certain likely directories as the likely places to find things. Now you are adding an extra possible search place. You can see what is already set by opening Konsole and typing echo $PATH

    To add paths to your PATH, simply create a file named $HOME/.config/plasma-workspace/env/path.sh with a contents similar to this:

    export PATH=$HOME/local/bin:$PATH

    Let's explore that. The command export tells the system that this is something that should be saved and used when looking for files. Next you add the full name of the directory you want to add (in this case $HOME/local/bin). Finally you see the $PATH variable itself - that's because you want to add your new path into it, not replace the existing path.

    Warning

    If you want to point your home don't use '~', use $HOME instead


    Often that will work well enough for you, but as you get more familiar with the system you will probably want to have the same environment when using a console or accessing your machine via ssh, you will need to add to the end of your .bashrc something like this:

    source $HOME/.config/plasma-workspace/env/path.sh

    You can also check how Plasma actually does it. It's done in your local startkde, which normally you can find in /usr/bin/startkde. If you are interested in reading the code, you can can view it online. Just search the file for environment variables.