0

tl;dr version

I added:

PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/x86_64-linux-gnu"

to ~/.profile and saved the file, closed and re-opened Terminal and echo $PKG_CONFIG_PATH gave me a blank line.

Details

I am very new to Linux and Ubuntu.

I am using Terminal to run cargo install cargo-embed. I got an error:

Unable to find libudev: 
pkg-config exited with status code 1
> PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags libudev

The system library libudev required by crate hidapi was not found. The file libudev.pc needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory. The PKG_CONFIG_PATH environment variable is not set.

HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing libudev.pc.

I have installed the library so I tried to set PKG_CONFIG_PATH.

First, I ran echo $PKG_CONFIG_PATH to confirm and got a blank line. Then I ran gedit ~/.profile as suggested in an answer about setting environment variables permanently. At the end of the file, I added:

PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/x86_64-linux-gnu"

and saved the file. I then ran source ~/.profile and re-ran echo $PKG_CONFIG_PATH to confirm and got

/usr/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/x86_64-linux-gnu

I then accidentally closed the terminal window and when I opened a new one and tried cargo install cargo-embed I got the same error. I ran echo $PKG_CONFIG_PATH again and got a blank line.

If I run source ~/.profile it imports but when I close and re-open Terminal it's not there. I tried just adding echo "Test" near the start of the .profile file to see if it's running. I see it when I run source ~/.profile but I don't see it when I open the Terminal. But then I don't know if I should see it. Like, I said, I'm very new to Ubuntu

Clarification

I have got past the cargo installation problem. I'd still like to know why this didn't work and how to add an environment variable permanently.

  • 2
    You seem to want to add it to the ~/.bashrc file instead ... based on your expectations – Raffa Jan 02 '24 at 16:09
  • 1
    How did you install the library? if you installed the libudev-dev development package from the Ubuntu repository then its .pc file should be in the default pc_path (which you can examine with pkg-config --variable pc_path pkg-config) - it shouldn't be necessary to use the PKG_CONFIG_PATH variable here at all. – steeldriver Jan 02 '24 at 16:27
  • @steeldriver - I did get past that. The question is why didn't the environment variable work. – serialhobbyist Jan 02 '24 at 16:40
  • OK so your terminal emulator likely invokes a non-login interactive shell, which (as @Raffa points out) reads your .bashrc not .profile - see for example Why isn't .profile sourced when opening a terminal? – steeldriver Jan 02 '24 at 16:46
  • @Raffa - yep, that was it. Linux people do like to make things difficult for the beginner, don't they? :-) – serialhobbyist Jan 02 '24 at 16:48
  • :D … "meticulous" is the word I guess … I too hear things about Linux people, but over my short stay here of 4 years I found they seem to "oddly enough" mostly favor simplicity with practicality over sophistication … Welcome to AskUbuntu.com – Raffa Jan 02 '24 at 17:22
  • @Raffa Thanks. Deffo wasn't having a go at anyone here, more at the person who decided that .bashrc was a name which clearly communicated its intent. – serialhobbyist Jan 02 '24 at 19:04

1 Answers1

0

As @Raffa stated in their comment, I should've been using ~/.bashrc instead of ~/.profile.