New path question

Forum Forums New users New Users and General Questions New path question

  • This topic has 19 replies, 6 voices, and was last updated Dec 26-11:29 pm by Brian Masinick.
Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #79879
    Member
    Raziel408

      Hi, I wish to add a a new directory to my path variable. I tried adding the line:
      export PATH=$PATH:’somepath’
      to .bashrc, .profile, /etc/profile.d and .desktop-session/startup
      Adding it to bashrc works but only for… well bash terminals. I need to add it to the window manager because If I start emacs the commands from ‘somepath’ are not available from emacs.

      #79880
      Moderator
      Brian Masinick
        Helpful
        Up
        0
        ::

        Ah, here’s the best way:

        Put the primary PATH you want to use in your $HOME/. profile.

        If it’s not in whatever you want, then execute the command
        source $HOME/.profile
        and you’ll get the correct path.

        You can put it elsewhere if it’s convenient and you can always create any simple script and execute it to either temporarily or permanently set up the path. You can execute that script from any login config files, including .profile or .bashrc.

        Clearly there is more than one way that will work; the example I provided certainly works.

        • This reply was modified 1 year, 1 month ago by Brian Masinick.

        --
        Brian Masinick

        #79914
        Member
        Raziel408
          Helpful
          Up
          0
          ::

          I’ve tried adding the lines to $HOME/.profile with no success. $HOME/.bashrc Only works for bash terminals. So if I start emacs from the menu the new path is ignored. I could run the script after I start emacs, but that’s ugly.

          • This reply was modified 1 year, 1 month ago by Raziel408.
          #79917
          Member
          PPC
            Helpful
            Up
            0
            ::

            I used duckduckgo to search for “add to path linux”. The very first hit was this: https://www.howtogeek.com/658904/how-to-add-a-directory-to-your-path-in-linux/
            (note I did not test the indicated procedure)

            Please try the steps pointed out there and report back- either if it works or any problems you may have…

            P.

            #79930
            Moderator
            Brian Masinick
              Helpful
              Up
              0
              ::

              I’ve tried adding the lines to $HOME/.profile with no success. $HOME/.bashrc Only works for bash terminals. So if I start emacs from the menu the new path is ignored. I could run the script after I start emacs, but that’s ugly.

              I have a path already established, but I wanted to set another specific path to run this example, so I typed in:

              PATH=/usr/bin:/home/masinick/bin emacs .

              The result was that the GNU Emacs editor started, and showed two visual windows, one with a directory listing of the current directory (.), and the other the Welcome to GNU Emacs screen. To display only the current directory, I then typed the Emacs key sequence C-x 1 (Ctrl X, followed by the number 1) and then the dired (directory listing) of the current directory was displayed.

              To get to a shell in the GUI version of Emacs, M-x shell opened a shell and typed

              echo $PATH — result below:

              /usr/bin:/home/masinick/bin:/home/masinick/bin

              This proves that though I had a DIFFERENT default PATH in my main shell, when I prepended the desired PATH prior to the command, it properly followed UNIX and Linux convention, and sent the specified command to the program I called, namely GNU Emacs, and the emacs command also recognized the pattern – the dot told it to open emacs with the current directory as the argument.

              Does this make sense to you, and is it helpful?

              --
              Brian Masinick

              #79934
              Member
              Raziel408
                Helpful
                Up
                0
                ::

                It makes sense.
                If I start a shell in emacs the path its also right (the one I added in bashrc) but if I use M-! echo $PATH (emacs shell command) the path is wrong. I need that the path of shell-command to be right to be able to use the compiler in the new path from emacs.
                Running PATH=$PATH:newpath emacs works indeed. But it’s not an optimal solution.

                #79937
                Moderator
                Brian Masinick
                  Helpful
                  Up
                  0
                  ::

                  I understand.

                  To make sure you have the paths desired you can and should put them into at least one of your initial configuration files, either . profile, .bashrc or whatever config files you use for the environment you are running.
                  If they don’t run, you can explicitly source them and then the PATH environment will be updated.

                  The bash documentation describes all of this. Hopefully this explanation is also clear; if not, let me know what else would be helpful.

                  --
                  Brian Masinick

                  #79953
                  Member
                  Raziel408
                    Helpful
                    Up
                    0
                    ::

                    Of course you are helpful. I really appreciate the help.
                    I’ve tried to add the path to those files. If I add it to the .profile, it doesn’t work. I I add it to .bashrc, only works if I start emacs from a terminal emulator. If I start emacs from X (the window manager menu) the path is the default.
                    Thanks a lot, by the way.

                    • This reply was modified 1 year, 1 month ago by Raziel408.
                    #79966
                    Moderator
                    Brian Masinick
                      Helpful
                      Up
                      0
                      ::

                      Of course you are helpful. I really appreciate the help.
                      I’ve tried to add the path to those files. If I add it to the .profile, it doesn’t work. I I add it to .bashrc, only works if I start emacs from a terminal emulator. If I start emacs from X (the window manager menu) the path is the default.
                      Thanks a lot, by the way.

                      If you type source .profile from your home directory AND you have:

                      PATH=<path-1>:<path-2>... etc.
                      then export PATH in your .profile, when you explicitly source your profile, it’ll retain the path for anything invoked from the shell.

                      Anything started BEFORE either .profile or .bashrc are “sourced” will not have the environment variables used by the shell, so that’s why I showed you how you can PREPEND a PATH to any command that you start from a command line.

                      Written documentation and examples on writing effective scripts usually includes explicitly setting the environment variables (including the PATH environment) to use in that script instead of relying on the “parent environment” of whatever runs the tool, application, or script (at least that’s what I learned in my reading and training).

                      • This reply was modified 1 year, 1 month ago by Brian Masinick.

                      --
                      Brian Masinick

                      #79998
                      Member
                      Raziel408
                        Helpful
                        Up
                        0
                        ::

                        I used duckduckgo to search for “add to path linux”. The very first hit was this: https://www.howtogeek.com/658904/how-to-add-a-directory-to-your-path-in-linux/
                        (note I did not test the indicated procedure)

                        Please try the steps pointed out there and report back- either if it works or any problems you may have…

                        P.

                        I haven’t notice this post. Sorry. I checked that article. The only part that I didn’t try of the article was adding:

                        export PATH=$PATH:<newpath>

                        at the end of the /etc/profile path. This, in theory, should have the same behavior than adding an script to /etc/profile.d/ with the line:

                        export PATH=$PATH:<newpath>

                        and thats what happened. This changes the path for all terminals (ctr+alt+(f2-f6)) and not for the wm. Previously I was able to do this by changing the path in /etc/slim.conf but now that file is empty (like: here). Then I stopped caring for the other users and then I found another way by adding the export line to a startup file to some config file in my $HOME. But I can’t find that file anymore. I though it was .desktop-session/startup it didn’t worked.

                        #79999
                        Member
                        PPC
                          Helpful
                          Up
                          0
                          ::

                          I found another way by adding the export line to a startup file to some config file in my $HOME. But I can’t find that file anymore. I though it was .desktop-session/startup it didn’t worked.

                          I can probably help with that: antiX menu > Control Centre > “Edit [your Window Manager name] Settings” > “startup” tab
                          It should edit the startup file that is loaded every time you start your window manager…

                          P.

                          #80000
                          Member
                          Raziel408
                            Helpful
                            Up
                            0
                            ::

                            Thanks. I edited the .icewm/startup file.I know its been read because I also have the line:
                            setxkbmap -option ctrl:nocaps
                            And that line works no problem.
                            I the export lines are not working. I also tried adding a line:
                            alias emacs="PATH=$PATH:<newpath> emacs"
                            but didn’t work either.

                            #80001
                            Moderator
                            Brian Masinick
                              Helpful
                              Up
                              0
                              ::

                              It makes sense.
                              If I start a shell in emacs the path its also right (the one I added in bashrc) but if I use M-! echo $PATH (emacs shell command) the path is wrong. I need that the path of shell-command to be right to be able to use the compiler in the new path from emacs.
                              Running PATH=$PATH:newpath emacs works indeed. But it’s not an optimal solution.

                              Suppose you create a short abbreviation with an alias command to invoke emacs or whatever commands you want.

                              I use alias commands all the time to run my apt commands, for instance

                              alias ug=’sudo apt get update; sudo apt get dist upgrade’

                              You can do the same with lengthy PATH environments to perform commands with the right environment.

                              --
                              Brian Masinick

                              #80002
                              Member
                              Raziel408
                                Helpful
                                Up
                                0
                                ::

                                Well I might just add the export path variable to .bashrc, and start emacs from terminal. Until I find a better solution. Thanks for the replies!

                                #96175
                                Member
                                seriousness
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Why is ~/.profile not automatically sourced on login in antiX, as it is e.g. in Ubuntu?

                                Viewing 15 posts - 1 through 15 (of 20 total)
                                • You must be logged in to reply to this topic.