You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新手创建Rails应用时遇registry.yarnpkg.com解析错误求助

Fixing "getaddrinfo ENOTFOUND registry.yarnpkg.com" When Creating a Rails App

Hey there! I know how frustrating it is to hit a snag right when you're starting out with Rails—let's get this sorted out together. That error means your system can't resolve the Yarn registry's domain name, which is usually a network or DNS issue. Here are some practical steps to fix it:

1. Verify basic network connectivity

First, let's confirm if your machine can reach the Yarn registry at all. Open your terminal and run:

ping registry.yarnpkg.com

If you get "request timed out" or no responses, that confirms a DNS/network problem. If you do get valid responses, skip ahead to step 3.

2. Switch to a reliable public DNS server

Most often, this error pops up because your default DNS server can't locate the Yarn registry. Try switching to a trusted public DNS like Google's or Cloudflare's:

  • Windows: Go to Control Panel → Network and Sharing Center → Change adapter settings → Right-click your active network → Properties → Internet Protocol Version 4 (TCP/IPv4) → Use the following DNS server addresses: 8.8.8.8 and 8.8.4.4
  • macOS: Open System Settings → Network → Select your active network → Click "Details" → Go to the DNS tab → Click the + button to add 8.8.8.8 (you can remove old DNS entries if they're causing issues)
  • Linux: Edit /etc/resolv.conf and add nameserver 8.8.8.8, then restart your network service (e.g., sudo systemctl restart NetworkManager for Ubuntu-based distros)

After updating DNS, run the ping command again to confirm connectivity.

3. Clear Yarn's cache

Sometimes corrupted cached data can cause unexpected issues. Clear Yarn's cache with:

yarn cache clean

Then try creating your Rails app again:

rails new file_name

4. Use npm instead of Yarn (temporary workaround)

If Yarn continues to give you trouble, you can tell Rails to use npm for frontend dependencies instead. Run this command to create your app:

rails new file_name --skip-yarn --npm

This skips Yarn entirely and uses npm, which might bypass the registry resolution issue.

5. Check proxy settings (if applicable)

If you're on a work/school network that uses a proxy, Yarn might not be configured to use it properly:

  • To set a proxy for Yarn:
    yarn config set proxy http://your-proxy-url:port
    yarn config set https-proxy http://your-proxy-url:port
    
  • If you don't need a proxy, make sure you haven't accidentally set one:
    yarn config delete proxy
    yarn config delete https-proxy
    

Start with the DNS fix first—it's the most common cause of this error. You'll be up and running with your first Rails app in no time!

内容的提问来源于stack exchange,提问作者Samvita_Karkal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:21:12