0
# Configuration
1
2
Commands for managing yarn configuration, global packages, and development symlinks.
3
4
## Capabilities
5
6
### Configuration Management
7
8
Manage yarn configuration settings at global and project levels.
9
10
```bash { .api }
11
yarn config set <key> <value> [options] # Set configuration value
12
yarn config get <key> # Get configuration value
13
yarn config delete <key> [options] # Delete configuration key
14
yarn config list # List all configuration
15
yarn config current # Show current effective configuration
16
17
# Options:
18
--global, -g # Set global configuration (user-level)
19
```
20
21
**Usage Examples:**
22
23
```bash
24
# Set configuration values
25
yarn config set registry https://registry.npmjs.org
26
yarn config set cache-folder /tmp/yarn-cache
27
yarn config set network-timeout 300000
28
29
# Set global configuration
30
yarn config set registry https://npm.company.com --global
31
yarn config set ignore-engines true --global
32
33
# Get configuration values
34
yarn config get registry
35
yarn config get cache-folder
36
37
# List all configuration
38
yarn config list
39
40
# Show current effective configuration with sources
41
yarn config current
42
43
# Delete configuration
44
yarn config delete registry
45
yarn config delete network-timeout --global
46
```
47
48
### Common Configuration Options
49
50
```bash { .api }
51
# Registry settings
52
yarn config set registry <url> # Default package registry
53
yarn config set <scope>:registry <url> # Registry for scoped packages
54
55
# Cache settings
56
yarn config set cache-folder <path> # Cache directory location
57
yarn config set offline-mirror <path> # Offline cache location
58
59
# Network settings
60
yarn config set network-timeout <ms> # Network request timeout
61
yarn config set network-concurrency <number> # Concurrent network requests
62
63
# Installation behavior
64
yarn config set ignore-scripts <boolean> # Skip lifecycle scripts
65
yarn config set ignore-engines <boolean> # Ignore engines field
66
yarn config set ignore-platform <boolean> # Ignore platform checks
67
yarn config set flat <boolean> # Use flat dependency structure
68
69
# Workspace settings
70
yarn config set workspaces-experimental <boolean> # Enable workspace features
71
```
72
73
**Configuration Examples:**
74
75
```bash
76
# Corporate environment setup
77
yarn config set registry https://npm.company.com
78
yarn config set //npm.company.com/:_authToken ${NPM_TOKEN}
79
yarn config set strict-ssl false
80
81
# Development optimizations
82
yarn config set network-timeout 600000
83
yarn config set network-concurrency 16
84
yarn config set cache-folder ~/.yarn-cache
85
86
# Security settings
87
yarn config set ignore-scripts true
88
yarn config set audit-level moderate
89
```
90
91
### Global Package Management
92
93
Manage globally installed packages.
94
95
```bash { .api }
96
yarn global add <package> [options] # Install global package
97
yarn global remove <package> # Remove global package
98
yarn global list [options] # List global packages
99
yarn global upgrade [package] [options] # Upgrade global packages
100
yarn global bin # Show global bin directory
101
102
# Options for add:
103
--prefix <path> # Install to specific prefix
104
105
# Options for upgrade:
106
--latest # Upgrade to latest version (ignore semver)
107
```
108
109
**Usage Examples:**
110
111
```bash
112
# Install global packages
113
yarn global add yarn
114
yarn global add @vue/cli
115
yarn global add create-react-app
116
yarn global add typescript
117
118
# Remove global packages
119
yarn global remove create-react-app
120
yarn global remove @vue/cli
121
122
# List global packages
123
yarn global list
124
yarn global list --depth=0
125
126
# Upgrade global packages
127
yarn global upgrade
128
yarn global upgrade typescript
129
130
# Upgrade to latest versions (ignoring semver)
131
yarn global upgrade --latest
132
yarn global upgrade typescript --latest
133
134
# Show global bin directory
135
yarn global bin
136
137
# Add global bin to PATH
138
export PATH="$(yarn global bin):$PATH"
139
```
140
141
**Global Package Location:**
142
- **Linux/macOS**: `~/.config/yarn/global`
143
- **Windows**: `%LOCALAPPDATA%\Yarn\config\global`
144
- **Binaries**: `$(yarn global bin)` directory
145
146
### Link Management
147
148
Create and manage symlinks for local development.
149
150
```bash { .api }
151
yarn link [package] # Link package from current directory
152
yarn unlink [package] # Unlink package
153
```
154
155
**Usage Examples:**
156
157
```bash
158
# In package directory - register for linking
159
cd /path/to/my-package
160
yarn link
161
162
# In consumer project - link to registered package
163
cd /path/to/my-project
164
yarn link my-package
165
166
# Unlink package
167
yarn unlink my-package
168
169
# In package directory - unregister from linking
170
cd /path/to/my-package
171
yarn unlink
172
```
173
174
**Link Workflow:**
175
1. **Register package**: Run `yarn link` in package directory
176
2. **Link consumer**: Run `yarn link <package-name>` in consumer project
177
3. **Development**: Changes in package are immediately available in consumer
178
4. **Unlink**: Run `yarn unlink <package-name>` to restore normal dependency
179
180
**Link Registry Location:**
181
- **Linux/macOS**: `~/.config/yarn/link`
182
- **Windows**: `%LOCALAPPDATA%\Yarn\config\link`
183
184
## Configuration Files
185
186
### .yarnrc Configuration
187
188
Project-level configuration file (`.yarnrc`):
189
190
```bash
191
# Registry configuration
192
registry "https://npm.company.com"
193
"@company:registry" "https://npm.company.com"
194
195
# Cache settings
196
cache-folder "/tmp/yarn-cache"
197
offline-mirror "./offline-cache"
198
199
# Network settings
200
network-timeout 300000
201
network-concurrency 8
202
203
# Installation settings
204
ignore-scripts true
205
ignore-engines false
206
flat false
207
208
# Authentication
209
"//npm.company.com/:_authToken" "${NPM_TOKEN}"
210
```
211
212
### Global Configuration
213
214
Global configuration location:
215
- **Linux/macOS**: `~/.yarnrc`
216
- **Windows**: `%USERPROFILE%\.yarnrc`
217
218
```bash
219
# Global defaults
220
registry "https://registry.npmjs.org"
221
cache-folder "/Users/username/.yarn-cache"
222
disable-self-update-check true
223
ignore-engines true
224
```
225
226
### Environment Variables
227
228
Yarn respects environment variables for configuration:
229
230
```bash { .api }
231
# Cache directory
232
YARN_CACHE_FOLDER=/path/to/cache
233
234
# Registry settings
235
YARN_REGISTRY=https://registry.npmjs.org
236
237
# Network settings
238
YARN_NETWORK_TIMEOUT=300000
239
YARN_NETWORK_CONCURRENCY=8
240
241
# Disable features
242
YARN_DISABLE_SELF_UPDATE_CHECK=true
243
YARN_ENABLE_OFFLINE_MODE=true
244
245
# Authentication
246
NPM_CONFIG_REGISTRY=https://npm.company.com
247
NPM_CONFIG__AUTH_TOKEN=${TOKEN}
248
249
# HTTP proxy
250
HTTP_PROXY=http://proxy.company.com:8080
251
HTTPS_PROXY=https://proxy.company.com:8080
252
```
253
254
## Registry Configuration
255
256
### Multiple Registries
257
258
```bash
259
# Default registry
260
yarn config set registry https://registry.npmjs.org
261
262
# Scoped registries
263
yarn config set @company:registry https://npm.company.com
264
yarn config set @internal:registry https://internal-npm.company.com
265
266
# Authentication for each registry
267
yarn config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
268
yarn config set //npm.company.com/:_authToken ${COMPANY_TOKEN}
269
```
270
271
### Registry Authentication
272
273
```bash
274
# Token-based authentication
275
yarn config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
276
277
# Basic authentication (base64 encoded username:password)
278
yarn config set //npm.company.com/:_auth ${BASE64_AUTH}
279
280
# Username/password authentication
281
yarn config set //npm.company.com/:username ${USERNAME}
282
yarn config set //npm.company.com/:_password ${BASE64_PASSWORD}
283
yarn config set //npm.company.com/:email ${EMAIL}
284
```
285
286
### SSL Configuration
287
288
```bash
289
# Disable SSL verification (not recommended for production)
290
yarn config set strict-ssl false
291
292
# Custom CA certificate
293
yarn config set ca-file /path/to/ca-cert.pem
294
295
# Custom certificate files
296
yarn config set cert-file /path/to/client-cert.pem
297
yarn config set key-file /path/to/client-key.pem
298
```
299
300
## Advanced Configuration
301
302
### Workspace Configuration
303
304
```bash
305
# Enable workspace features
306
yarn config set workspaces-experimental true
307
308
# Workspace-specific settings
309
yarn config set workspace-experimental true
310
yarn config set workspace-tools true
311
```
312
313
### Cache Configuration
314
315
```bash
316
# Cache settings
317
yarn config set cache-folder ~/.yarn-cache
318
yarn config set offline-mirror ./offline-packages
319
yarn config set disable-self-update-check true
320
321
# Cache cleanup
322
yarn config set cache-clean-interval 86400000 # 24 hours in ms
323
```
324
325
### Network Optimization
326
327
```bash
328
# Network performance
329
yarn config set network-timeout 600000 # 10 minutes
330
yarn config set network-concurrency 16 # Concurrent requests
331
yarn config set child-concurrency 8 # Child processes
332
333
# Retry settings
334
yarn config set network-retry-count 3
335
yarn config set network-retry-delay 1000
336
```
337
338
### Development Settings
339
340
```bash
341
# Development optimizations
342
yarn config set save-prefix "~" # Use tilde for version ranges
343
yarn config set ignore-scripts false # Allow lifecycle scripts
344
yarn config set ignore-engines false # Check engine compatibility
345
yarn config set ignore-platform false # Check platform compatibility
346
347
# Workspace development
348
yarn config set link-duplicates true # Link duplicate packages
349
yarn config set link-folder ~/.config/yarn/link # Link registry location
350
```
351
352
## Configuration Hierarchy
353
354
Yarn uses configuration in this priority order (highest to lowest):
355
356
1. **Command line flags**: `--registry https://example.com`
357
2. **Environment variables**: `YARN_REGISTRY=https://example.com`
358
3. **Project .yarnrc**: `./.yarnrc` in project directory
359
4. **Parent .yarnrc**: `../.yarnrc` (and up the directory tree)
360
5. **Global .yarnrc**: `~/.yarnrc` (user home directory)
361
6. **System .yarnrc**: `/etc/yarnrc` (system-wide, Linux/macOS only)
362
7. **Built-in defaults**: Yarn's default configuration
363
364
### Configuration Debugging
365
366
```bash
367
# Show effective configuration
368
yarn config list
369
370
# Show configuration sources
371
yarn config list --verbose
372
373
# Check specific configuration value
374
yarn config get registry
375
376
# Test configuration
377
yarn install --verbose # Shows which registry is being used
378
```
379
380
### Configuration Best Practices
381
382
**Project .yarnrc:**
383
```bash
384
# Project-specific settings only
385
registry "https://npm.company.com"
386
"@company:registry" "https://npm.company.com"
387
network-timeout 300000
388
```
389
390
**Global .yarnrc:**
391
```bash
392
# User preferences and defaults
393
cache-folder "/Users/username/.yarn-cache"
394
disable-self-update-check true
395
network-concurrency 8
396
save-prefix "^"
397
```
398
399
**Environment Variables (CI/CD):**
400
```bash
401
# In CI/CD environment
402
export YARN_CACHE_FOLDER=/tmp/yarn-cache
403
export YARN_REGISTRY=https://npm.company.com
404
export YARN_DISABLE_SELF_UPDATE_CHECK=true
405
export NPM_CONFIG__AUTH_TOKEN=${NPM_TOKEN}
406
```