在AWS EC2免费层Ubuntu虚拟机安装R包text2vec遇错误求助
Hey there, let’s work through this text2vec installation issue you’re hitting on your AWS EC2 Ubuntu free tier instance. From the partial log you shared, the source package downloaded successfully but failed mid-installation—this is almost always tied to missing system-level build dependencies or unmet R package requirements. Here’s how to resolve it step by step:
Step 1: Install System Build Dependencies
text2vec includes C++ extensions, so you need basic compilation tools and libraries that R uses to build source packages. Run these commands in your Ubuntu terminal:
sudo apt update && sudo apt install build-essential libcurl4-openssl-dev libssl-dev libxml2-dev
This installs the GNU compiler collection, plus libraries for handling SSL, HTTP requests, and XML—all common prerequisites for R packages with compiled components.
Step 2: Install Required R Dependencies
text2vec relies on several other R packages to function. Before installing text2vec itself, make sure these are installed first (with full dependencies):
install.packages(c("data.table", "stringi", "magrittr", "Matrix", "Rcpp", "RcppParallel"), dependencies = TRUE)
These packages handle data manipulation, string processing, parallel computing, and C++ integration—core components text2vec needs to build and run.
Step 3: Reinstall text2vec
Now try installing text2vec again. You might not need to specify type = "source"—R will automatically pick the best package format (binary if available, source if not) for your system:
install.packages("text2vec")
If you specifically need the source version (e.g., for the latest features), run:
install.packages("text2vec", type = "source")
Step 4: Check R Version Compatibility (If Issues Persist)
The text2vec 0.5.1 version you’re trying to install requires R 3.5.0 or newer. To check your current R version, run:
R --version
If your R version is outdated, update it with these steps:
- Add the official CRAN repository to your system:
echo "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" | sudo tee -a /etc/apt/sources.list.d/r-project.list - Import the CRAN GPG key to verify package integrity:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 - Update and install the latest R version:
sudo apt update && sudo apt install r-base r-base-dev
After updating, repeat steps 2 and 3 to install text2vec.
内容的提问来源于stack exchange,提问作者Christopher Costello

