Not-Root-User

在 NetBSD 的主目錄中使用 pkgsrc

  • April 16, 2017

我是 NetBSD 的新手,雖然經常在 ubuntu 上使用 pkgsrc。我可以從原始碼建構和安裝包,而不會對 ubuntu 的包依賴項產生任何影響。

例如,即使 ruby​​ 2.2 是通過 apt-get 安裝的,我也可以$HOME/pkg/bin通過 pkgsrc 建構並安裝 ruby​​ 2.3。我可以使用 ruby​​ 2.3 沒有任何依賴問題。

這個特性對我很有幫助,這就是我喜歡 pkgsrc 的原因。

現在我將 NetBSD 7.1 安裝到我的另一台 PC 上。我想下載 pkgsrc 作為我自己的包管理器,並想將包建構到我的主目錄($HOME/pkg/bin)中,而不像我在 ubuntu 上所做的那樣對系統範圍產生任何影響,即使 NetBSD 本身使用 pkgsrc。

當我在主目錄中嘗試./bootstrap --unpriviledged時,它不起作用。在我用詳細的錯誤資訊問為什麼之前,讓我問一下 NetBSD 是否設計或考慮過為每個使用者下載和使用另一個 pkgsrc 而對系統環境沒有任何影響。

PS 英語不是我的母語;請原諒打字、語法或/和單詞選擇錯誤。

更新(2017/04/08)

感謝 Greg A. Woods 的回答,我明白我必須顯示詳細的錯誤消息。

起初,我總是使用 pkg_add 和 root 帳戶從二進制安裝。

-bash-4.4$ uname -a
NetBSD hello-netbsd 7.1 NetBSD 7.1 (GENERIC.201703111743Z) amd64


-bash-4.4$ pkg_info -a
sudo-1.8.17p1       Allow others to run commands as root
bash-4.4.012        The GNU Bourne Again Shell
cvs-1.12.13nb4      Concurrent Versions System
gcc6-6.3.0          The GNU Compiler Collection (GCC) - 6 Release Series

然後我以非 root 使用者身份登錄,下載了 pkgsrc 和引導程序。

-bash-4.4$ cvs -q -z2 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -r pkgsrc-2017Q1 -P pkgsrc
-bash-4.4$ cd pkgsrc/bootstrap
-bash-4.4$ ./bootstrap --unprivileged
...
...
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/vagrant/pkgsrc/bootstrap/work/bmake':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
===> exited with status 1
aborted.

我修改了$PATH.

-bash-4.4$ vi ~/.profile
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R7/bin:/usr/X11R6/bin:/usr/pkg/bin
PATH=${PATH}:/usr/pkg/sbin:/usr/games:/usr/local/bin:/usr/local/sbin
GCC_PATH=/usr/pkg/gcc6/bin
PATH=${PATH}:${GCC_PATH}

-bash-4.4$  . ~/.profile
-bash-4.4$  echo $PATH
/home/vagrant/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R7/bin:/usr/X11R6/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/games:/usr/local/bin:/usr/local/sbin:/usr/pkg/gcc6/bin

然後再試一次。

-bash-4.4$ rm -fr work 
-bash-4.4$ ./bootstrap --unprivileged
...
...
checking for gcc... gcc
checking for C compiler default output file name... 
configure: error: in `/home/vagrant/pkgsrc/bootstrap/work/bmake':
configure: error: C compiler cannot create executables
See `config.log' for more details.
===> exited with status 77
aborted.

config.log 是這樣的:

-bash-4.4$ view work/bmake/config.log

     1 This file contains any messages produced by compilers while
     2 running configure, to aid debugging if configure makes a mistake.
     3 
     4 It was created by bmake configure 20140214, which was
     5 generated by GNU Autoconf 2.64.  Invocation command line was
     6 
     7   $ configure --prefix=/home/vagrant/pkgsrc/bootstrap/work --with-default-sys-path=/home/vagrant/pkgsrc/bootstrap/work
/share/mk --with-machine-arch=x86_64
     8 
     9 ## --------- ##
    10 ## Platform. ##
    11 ## --------- ##
    12
    13 hostname = hello-netbsd
    14 uname -m = amd64
    15 uname -r = 7.1
    16 uname -s = NetBSD
    17 uname -v = NetBSD 7.1 (GENERIC.201703111743Z)
    18
    19 /usr/bin/uname -p = x86_64
    20 /bin/uname -X     = unknown
    21
    22 /bin/arch              = unknown
    23 /usr/bin/arch -k       = unknown
    24 /usr/convex/getsysinfo = unknown
    25 /usr/bin/hostinfo      = unknown
    26 /bin/machine           = unknown
    27 /usr/bin/oslevel       = unknown
    28 /bin/universe          = unknown
    29
    30 PATH: /home/vagrant/pkg/bin
    31 PATH: /home/vagrant/pkg/sbin
    32 PATH: .
    33 PATH: /home/vagrant/bin
    34 PATH: /bin
    34 PATH: /bin
    35 PATH: /sbin
    36 PATH: /usr/bin
    37 PATH: /usr/sbin
    38 PATH: /usr/X11R7/bin
    39 PATH: /usr/X11R6/bin
    40 PATH: /usr/pkg/bin
    41 PATH: /usr/pkg/sbin
    42 PATH: /usr/games
    43 PATH: /usr/local/bin
    44 PATH: /usr/local/sbin
    45 PATH: /usr/pkg/gcc6/bin
    46 PATH: /sbin
    47 PATH: /usr/sbin
    48
    49 
    50 ## ----------- ##
    51 ## Core tests. ##
    52 ## ----------- ##
    53 
    54 configure:2371: checking for gcc
    55 configure:2387: found /usr/pkg/gcc6/bin/gcc
    56 configure:2398: result: gcc
    57 configure:2627: checking for C compiler version
    58 configure:2636: gcc --version >&5
    59 gcc (GCC) 6.3.0
    60 Copyright (C) 2016 Free Software Foundation, Inc.
    61 This is free software; see the source for copying conditions.  There is NO
    62 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    63 
    64 configure:2647: $? = 0
    65 configure:2636: gcc -v >&5
    66 Using built-in specs.
    67 COLLECT_GCC=gcc
    68 COLLECT_LTO_WRAPPER=/usr/pkg/gcc6/libexec/gcc/x86_64--netbsd/6.3.0/lto-wrapper
    69 Target: x86_64--netbsd
    70 Configured with: ../gcc-6.3.0/configure --disable-libstdcxx-pch --enable-nls --with-libiconv-prefix=/usr --enable-__cx
a_atexit --with-gxx-include-dir=/usr/pkg/gcc6/include/c++/ --enable-languages='c obj-c++ objc fortran c++' --enable-shared --e
nable-long-long --with-local-prefix=/usr/pkg/gcc6 --disable-libssp --enable-threads=posix --with-boot-ldflags='-static-libstdc
++ -static-libgcc -Wl,-R/usr/pkg/lib ' --with-arch=nocona --with-tune=nocona --with-fpmath=sse --with-gnu-ld --with-ld=/usr/bi
n/ld --with-gnu-as --with-as=/usr/bin/as --prefix=/usr/pkg/gcc6 --build=x86_64--netbsd --host=x86_64--netbsd --infodir=/usr/pk
g/gcc6/info --mandir=/usr/pkg/gcc6/man
    71 Thread model: posix
    72 gcc version 6.3.0 (GCC)
    73 configure:2647: $? = 0
    74 configure:2636: gcc -V >&5
    75 gcc: error: unrecognized command line option '-V'
    76 gcc: fatal error: no input files
    77 compilation terminated.
    78 configure:2647: $? = 1
    79 configure:2636: gcc -qversion >&5
    80 gcc: error: unrecognized command line option '-qversion'; did you mean '--version'?
    81 gcc: fatal error: no input files
    82 compilation terminated.
    83 configure:2647: $? = 1
    84 configure:2669: checking for C compiler default output file name
    85 configure:2691: gcc    conftest.c  >&5
    86 In file included from conftest.c:9:0:
    87 /usr/pkg/gcc6/lib/gcc/x86_64--netbsd/6.3.0/include-fixed/stdio.h:54:23: fatal error: sys/cdefs.h: No such file or dire
ctory
    88  #include <sys/cdefs.h>
    89                        ^
    90 compilation terminated.
    91 configure:2695: $? = 1
    92 configure:2732: result:
    93 configure: failed program was:
    94 | /* confdefs.h */
    95 | #define PACKAGE_NAME "bmake"
    96 | #define PACKAGE_TARNAME "bmake"
    97 | #define PACKAGE_VERSION "20140214"
    98 | #define PACKAGE_STRING "bmake 20140214"
    99 | #define PACKAGE_BUGREPORT "sjg@NetBSD.org"
   100 | #define PACKAGE_URL ""
   101 | /* end confdefs.h.  */
   102 | #include <stdio.h>
   103 | int
   104 | main ()
   105 | {
   106 | FILE *f = fopen ("conftest.out", "w");
   107 |  return ferror (f) || fclose (f) != 0;
   108 |
   109 |   ;
   110 |   return 0;
   111 | }
   112 configure:2738: error: in `/home/vagrant/pkgsrc/bootstrap/work/bmake':
   113 configure:: error: C compiler cannot create executables
   114 See `config.log' for more details.
   115
   116 ## ---------------- ##
   117 ## Cache variables. ##
   118 ## ---------------- ##
   119
   120 ac_cv_env_CC_set=
   121 ac_cv_env_CC_value=
   122 ac_cv_env_CFLAGS_set=
   123 ac_cv_env_CFLAGS_value=
   124 ac_cv_env_CPPFLAGS_set=
   125 ac_cv_env_CPPFLAGS_value=
   126 ac_cv_env_CPP_set=
   127 ac_cv_env_CPP_value=
   128 ac_cv_env_LDFLAGS_set=
   129 ac_cv_env_LDFLAGS_value=
   130 ac_cv_env_LIBS_set=
   131 ac_cv_env_LIBS_value=
   132 ac_cv_env_build_alias_set=
   133 ac_cv_env_build_alias_value=
   134 ac_cv_env_host_alias_set=
   135 ac_cv_env_host_alias_value=
   136 ac_cv_env_target_alias_set=
   137 ac_cv_env_target_alias_value=
   138 ac_cv_prog_ac_ct_CC=gcc
   139
   140 ## ----------------- ##
   141 ## Output variables. ##
   142 ## ----------------- ##
   143
   144 CC='gcc'
   145 CFLAGS=''
   146 CPP=''
   147 CPPFLAGS=''
   148 DEFS=''
   149 ECHO_C=''
   150 ECHO_N='-n'
   151 ECHO_T=''
   152 EGREP=''
   153 EXEEXT=''
   154 GCC=''
   155 GREP=''
   156 INSTALL=''
   157 INSTALL_DATA=''
   158 INSTALL_PROGRAM=''
   159 INSTALL_SCRIPT=''
   160 LDFLAGS=''
   161 LIBOBJS=''
   162 LIBS=''
   163 LTLIBOBJS=''
   164 OBJEXT=''
   165 PACKAGE_BUGREPORT='sjg@NetBSD.org'
   166 PACKAGE_NAME='bmake'
   167 PACKAGE_STRING='bmake 20140214'
   168 PACKAGE_TARNAME='bmake'
   169 PACKAGE_URL=''
   170 PACKAGE_VERSION='20140214'
   171 PATH_SEPARATOR=':'
   172 SHELL='/bin/sh'
   173 ac_ct_CC='gcc'
   174 ac_exe_suffix=''
   175 bindir='${exec_prefix}/bin'
   176 bmake_path_max=''
   177 build_alias=''
   178 datadir='${datarootdir}'
   179 datarootdir='${prefix}/share'
   180 default_sys_path=''
   181 diff_u=''
   182 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
   183 dvidir='${docdir}'
   184 exec_prefix='NONE'
   185 filemon_h='no'
   186 force_machine=''
   187 host_alias=''
   188 htmldir='${docdir}'
   189 includedir='${prefix}/include'
   190 infodir='${datarootdir}/info'
   191 libdir='${exec_prefix}/lib'
   192 libexecdir='${exec_prefix}/libexec'
   193 localedir='${datarootdir}/locale'
   194 localstatedir='${prefix}/var'
   195 machine=''
   196 machine_arch=''
   197 mandir='${datarootdir}/man'
   198 mksrc=''
   199 oldincludedir='/usr/include'
   200 pdfdir='${docdir}'
   201 prefix='/home/vagrant/pkgsrc/bootstrap/work'
   202 program_transform_name='s,x,x,'
   203 psdir='${docdir}'
   204 sbindir='${exec_prefix}/sbin'
   205 sharedstatedir='${prefix}/com'
   206 sysconfdir='${prefix}/etc'
   207 target_alias=''
   208 use_meta='yes'
   209
   210 ## ----------- ##
   211 ## confdefs.h. ##
   212 ## ----------- ##
   213
   214 /* confdefs.h */
   215 #define PACKAGE_NAME "bmake"
   216 #define PACKAGE_TARNAME "bmake"
   217 #define PACKAGE_VERSION "20140214"
   218 #define PACKAGE_STRING "bmake 20140214"
   219 #define PACKAGE_BUGREPORT "sjg@NetBSD.org"
   220 #define PACKAGE_URL ""
   221
   222 configure: exit 77

我猜想有些文件失去了,但不知道該怎麼做。

update2(2017/04/11) 以下是 `gcc -v’ 的結果

-bash-4.4$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/pkg/gcc6/libexec/gcc/x86_64--netbsd/6.3.0/lto-wrapper
Target: x86_64--netbsd
Configured with: ../gcc-6.3.0/configure --disable-libstdcxx-pch --enable-nls --with-libiconv-prefix=/usr --enable-__cxa_atexit --with-gxx-include-dir=/usr/pkg/gcc6/include/c++/ --enable-languages='c obj-c++ objc fortran c++' --enable-shared --enable-long-long --with-local-prefix=/usr/pkg/gcc6 --disable-libssp --enable-threads=posix --with-boot-ldflags='-static-libstdc++ -static-libgcc -Wl,-R/usr/pkg/lib ' --with-arch=nocona --with-tune=nocona --with-fpmath=sse --with-gnu-ld --with-ld=/usr/bin/ld --with-gnu-as --with-as=/usr/bin/as --prefix=/usr/pkg/gcc6 --build=x86_64--netbsd --host=x86_64--netbsd --infodir=/usr/pkg/gcc6/info --mandir=/usr/pkg/gcc6/man
Thread model: posix
gcc version 6.3.0 (GCC) 

我在安裝過程中選擇了最小安裝。那是錯的嗎?

始終提供詳細的錯誤消息!(或者至少足以提供關於遇到什麼實際問題的線索,因為這樣可以避免不必要的額外交流——如果沒有足夠的資訊來提供任何有意義的方向,許多人會簡單地忽略問題)

無論如何,./bootstrap --unprivileged應該在 NetBSD 主機上工作(它對我有用)。

不過,我不確定這是個好主意。有些東西不會(也不能)以非特權模式安裝,因為它們必須修改系統文件或安裝 setuid 等。

我以普通使用者的身份建構軟體包,但始終將它們安裝為root.

看起來您沒有為 netbsd 安裝“comp”集,即 C 編譯器(等)。嘗試執行“gcc -v”。

FWIW,最好的 NetBSD 和 pkgsrc 幫助是通過郵件列表實現的,我只是偶然看到這裡,通過http://netbsd.fi/

引用自:https://unix.stackexchange.com/questions/355229