Can't install devtools in WSL2

I can't seem to install devtools under WSL2 / Ubuntu 20.04 / Windows 10.

The apparent error message is about xml2 but quite a bit of googling suggests that at least part of the problem is the location of the libxml2 installation or the libxml2-dev installation, both of which appear to be standard to me.

> install.packages("devtools")
Installing package into ‘/home/mcq/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
also installing the dependencies ‘xml2’, ‘roxygen2’, ‘rversions’

trying URL 'https://cran.microsoft.com/src/contrib/xml2_1.3.3.tar.gz'
Content type 'application/octet-stream' length 283965 bytes (277 KB)
==================================================
downloaded 277 KB

trying URL 'https://cran.microsoft.com/src/contrib/roxygen2_7.1.2.tar.gz'
Content type 'application/octet-stream' length 267337 bytes (261 KB)
==================================================
downloaded 261 KB

trying URL 'https://cran.microsoft.com/src/contrib/rversions_2.1.1.tar.gz'
Content type 'application/octet-stream' length 42064 bytes (41 KB)
==================================================
downloaded 41 KB

trying URL 'https://cran.microsoft.com/src/contrib/devtools_2.4.3.tar.gz'
Content type 'application/octet-stream' length 372413 bytes (363 KB)
==================================================
downloaded 363 KB

* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/usr/include/libxml2
Using PKG_LIBS=-lxml2
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c connection.cpp -o connection.o
gcc -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_doc.cpp -o xml2_doc.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_init.cpp -o xml2_init.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_namespace.cpp -o xml2_namespace.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_node.cpp -o xml2_node.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_output.cpp -o xml2_output.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_schema.cpp -o xml2_schema.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_url.cpp -o xml2_url.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_xpath.cpp -o xml2_xpath.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o xml2.so connection.o init.o xml2_doc.o xml2_init.o xml2_namespace.o xml2_node.o xml2_output.o xml2_schema.o xml2_url.o xml2_xpath.o -lxml2 -L/usr/lib/R/lib -lR
installing to /home/mcq/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-xml2/00new/xml2/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
mv: cannot move '/home/mcq/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-xml2/00new/xml2' to '/home/mcq/R/x86_64-pc-linux-gnu-library/4.1/xml2': Permission denied
ERROR:   moving to final location failed

I'm not sure if I should post more contextual info about this but would be happy to do so.

You have a permissions issue, make sure your user has permission to write into that folder or run the install command as sudo.

This has nothing to do with libxml2 system library which is correctly detected.

Thanks, but that doesn't seem to be the problem but rather a symptom.

First, I've installed 117 packages into that location successfully. I can manually create and delete files there. By monitoring the location during the failed devtools installation, I can see that the 00LOCK-xml2 folder is created then removed from that location.

Second, here is the output when I run R with sudo:

> install.packages("devtools")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘xml2’, ‘roxygen2’, ‘rversions’

trying URL 'https://cloud.r-project.org/src/contrib/xml2_1.3.3.tar.gz'
Content type 'application/x-gzip' length 283965 bytes (277 KB)
==================================================
downloaded 277 KB

trying URL 'https://cloud.r-project.org/src/contrib/roxygen2_7.1.2.tar.gz'
Content type 'application/x-gzip' length 267337 bytes (261 KB)
==================================================
downloaded 261 KB

trying URL 'https://cloud.r-project.org/src/contrib/rversions_2.1.1.tar.gz'
Content type 'application/x-gzip' length 42064 bytes (41 KB)
==================================================
downloaded 41 KB

trying URL 'https://cloud.r-project.org/src/contrib/devtools_2.4.3.tar.gz'
Content type 'application/x-gzip' length 372413 bytes (363 KB)
==================================================
downloaded 363 KB

* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/usr/include/libxml2
Using PKG_LIBS=-lxml2
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c connection.cpp -o connection.o
gcc -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_doc.cpp -o xml2_doc.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_init.cpp -o xml2_init.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_namespace.cpp -o xml2_namespace.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_node.cpp -o xml2_node.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_output.cpp -o xml2_output.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_schema.cpp -o xml2_schema.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_url.cpp -o xml2_url.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0    -fvisibility=hidden -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_xpath.cpp -o xml2_xpath.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o xml2.so connection.o init.o xml2_doc.o xml2_init.o xml2_namespace.o xml2_node.o xml2_output.o xml2_schema.o xml2_url.o xml2_xpath.o -lxml2 -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-xml2/00new/xml2/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
mv: cannot move '/usr/local/lib/R/site-library/00LOCK-xml2/00new/xml2' to '/usr/local/lib/R/site-library/xml2': Permission denied
ERROR:   moving to final location failed
ERROR: dependency ‘xml2’ is not available for package ‘roxygen2’
* removing ‘/usr/local/lib/R/site-library/roxygen2’
ERROR: dependency ‘xml2’ is not available for package ‘rversions’
* removing ‘/usr/local/lib/R/site-library/rversions’
ERROR: dependencies ‘roxygen2’, ‘rversions’ are not available for package ‘devtools’
* removing ‘/usr/local/lib/R/site-library/devtools’

The downloaded source packages are in
        ‘/tmp/RtmpIhpjrk/downloaded_packages’
Warning messages:
1: In install.packages("devtools") :
  installation of package ‘xml2’ had non-zero exit status
2: In install.packages("devtools") :
  installation of package ‘roxygen2’ had non-zero exit status
3: In install.packages("devtools") :
  installation of package ‘rversions’ had non-zero exit status
4: In install.packages("devtools") :
  installation of package ‘devtools’ had non-zero exit status
>

As you can see, there is an analogous error message. Again, I've installed many packages to that site previously, so my sudo user has permissions there. I suspect that the permission error is caused by something that is created in the 00LOCK-xml2 directory, but it is removed so quickly in the process, that I can't see it.

Well, sadly, all the error message is telling us is that you don't have permissions to write there so hard to know what else might be going on with the information we have.

I can install the xml2 package on the same setup (WSL2 / Ubuntu 20.04 / Windows 10) without any issues so very likely this is a configuration problem specific to your system.

I was successful in this install, following some advice on StackOverflow, to say

install.packages("xml2", dependencies=TRUE, INSTALL_opts = c('--no-lock'))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.