refactor: make Node.js installation automatic in setup.sh
- setup.sh now automatically installs Node 22 via NodeSource if not found - No more separate manual Node installation step required - Simplified to single command: bash scripts/setup.sh - Works for apt/pacman/brew systems - Updated SETUP_GUIDE.md with simplified instructions - Better logging during Node installation process Users can now simply run: bash scripts/setup.sh And everything (including Node 22) will be installed automatically.
This commit is contained in:
+77
-80
@@ -6,74 +6,74 @@ Officer is a self-hosted AI intranet for teams. This guide covers fresh installa
|
|||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
Officer uses **system-wide Node.js** to ensure all users have consistent access to tools:
|
Officer uses **system-wide Node.js v22** to ensure all users have consistent access:
|
||||||
|
|
||||||
```
|
```
|
||||||
System Node.js (v22, system-wide)
|
System Node.js v22 (/usr/bin/node)
|
||||||
↓
|
↓
|
||||||
npm global packages → /usr/local/lib/node_modules/
|
All users automatically get:
|
||||||
├── pi (coding agent)
|
├── node, npm, bun
|
||||||
├── claude (Claude Code)
|
├── pi, claude (coding agents)
|
||||||
└── (available to all users)
|
├── go, rustc (compilers)
|
||||||
|
└── All tools and services
|
||||||
|
|
||||||
Systemd Services
|
Systemd Services (use system Node)
|
||||||
├── officer-pty-sidecar (terminal backend)
|
├── officer-pty-sidecar
|
||||||
|
├── officer (main server)
|
||||||
└── (other services)
|
└── (other services)
|
||||||
```
|
```
|
||||||
|
|
||||||
This is **not** an nvm-based setup. Each user doesn't install their own Node version. Instead:
|
**Benefits:**
|
||||||
- One system Node.js for everyone
|
- One Node version for everyone (no conflicts)
|
||||||
- All npm packages installed system-wide
|
- New users automatically get same setup
|
||||||
- Simple, predictable, production-friendly
|
- Services use consistent environment
|
||||||
|
- Simple to maintain and troubleshoot
|
||||||
|
- Automatic installation (setup.sh handles it)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Installation Steps
|
## Installation Steps
|
||||||
|
|
||||||
### 1. Install Node.js 22 (System-Wide)
|
### Quick Start (One Command)
|
||||||
|
|
||||||
**On fresh Ubuntu/Debian:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Add NodeSource repository for Node 22 LTS
|
|
||||||
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
|
||||||
|
|
||||||
# Install Node.js and npm
|
|
||||||
sudo apt-get install -y nodejs
|
|
||||||
|
|
||||||
# Verify for all users
|
|
||||||
node --version
|
|
||||||
npm --version
|
|
||||||
|
|
||||||
# Both should work regardless of which user runs it
|
|
||||||
```
|
|
||||||
|
|
||||||
**Already have an older Node version?**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# upgrade it
|
|
||||||
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
|
||||||
sudo apt-get install -y nodejs
|
|
||||||
|
|
||||||
# verify
|
|
||||||
node --version # Should be v22.x.x
|
|
||||||
```
|
|
||||||
|
|
||||||
**Coming from nvm?**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# If you installed via nvm before, remove it
|
|
||||||
# Then install system Node as above
|
|
||||||
# nvm is NOT needed for Officer production setup
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Run Setup Script
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /path/to/officer/monorepo
|
cd /path/to/officer/monorepo
|
||||||
bash scripts/setup.sh
|
bash scripts/setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
That's it! The script will:
|
||||||
|
- Install Node.js 22 automatically (if not found)
|
||||||
|
- Install all dependencies
|
||||||
|
- Setup all services
|
||||||
|
- Verify everything works
|
||||||
|
|
||||||
|
### What Happens Automatically
|
||||||
|
|
||||||
|
The setup script automatically:
|
||||||
|
1. Checks if Node 22 is installed
|
||||||
|
2. If not, sets up NodeSource repository and installs it
|
||||||
|
3. Installs all system packages, tools, and npm globals
|
||||||
|
4. Creates systemd services
|
||||||
|
5. Verifies everything works
|
||||||
|
|
||||||
|
**No manual Node installation needed!**
|
||||||
|
|
||||||
|
### Coming from nvm?
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# If you previously installed via nvm, you can remove it
|
||||||
|
# (optional, won't interfere)
|
||||||
|
rm -rf ~/.nvm
|
||||||
|
|
||||||
|
# Or keep it for local dev, but system Node will take precedence for services
|
||||||
|
```
|
||||||
|
|
||||||
|
The system Node (installed by setup.sh) will be used by:
|
||||||
|
- All users
|
||||||
|
- All systemd services
|
||||||
|
- All npm global packages
|
||||||
|
- Officer server itself
|
||||||
|
|
||||||
This will:
|
This will:
|
||||||
- Install all system dependencies (git, build tools, ffmpeg, etc.)
|
- Install all system dependencies (git, build tools, ffmpeg, etc.)
|
||||||
- Install Bun, Go, Rust
|
- Install Bun, Go, Rust
|
||||||
@@ -85,27 +85,27 @@ This will:
|
|||||||
|
|
||||||
**Note:** Setup script uses `sudo` for system-level installations. You'll be prompted for your password.
|
**Note:** Setup script uses `sudo` for system-level installations. You'll be prompted for your password.
|
||||||
|
|
||||||
### 3. Verify Installation
|
### Verify Installation
|
||||||
|
|
||||||
|
After setup.sh completes, verify as any user:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Everyone can use these (all users)
|
node --version # v22.x.x
|
||||||
which node # /usr/bin/node
|
which pi # /usr/bin/pi
|
||||||
which pi # /usr/bin/pi
|
which claude # /usr/bin/claude
|
||||||
which claude # /usr/bin/claude
|
which bun # /usr/local/bin/bun
|
||||||
which bun # /home/user/.bun/bin/bun (or /usr/local/bin/bun)
|
|
||||||
|
|
||||||
# Test that pi works
|
# Test Pi works
|
||||||
pi --version
|
|
||||||
pi --list-models
|
pi --list-models
|
||||||
|
|
||||||
# Test that Officer can start
|
# Test Officer can start
|
||||||
bun dev
|
bun dev
|
||||||
|
|
||||||
# In another terminal
|
# In another terminal, test API
|
||||||
curl http://localhost:5000/api/pi/models
|
curl http://localhost:5000/api/pi/models
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Start Officer
|
### Start Officer
|
||||||
|
|
||||||
**Development:**
|
**Development:**
|
||||||
```bash
|
```bash
|
||||||
@@ -171,26 +171,18 @@ The `officer-pty-sidecar` systemd service will still use `/usr/bin/node` (system
|
|||||||
|
|
||||||
### "node: command not found"
|
### "node: command not found"
|
||||||
|
|
||||||
**For a single user:**
|
This shouldn't happen if setup.sh ran successfully. But if it does:
|
||||||
```bash
|
|
||||||
# User's shell doesn't have node in PATH
|
|
||||||
# Make sure system Node is installed:
|
|
||||||
sudo apt-get install -y nodejs
|
|
||||||
node --version
|
|
||||||
```
|
|
||||||
|
|
||||||
**For systemd service:**
|
|
||||||
```bash
|
```bash
|
||||||
# Service can't find node
|
# Run setup script again — it will install Node if missing
|
||||||
sudo systemctl status officer-pty-sidecar
|
bash scripts/setup.sh
|
||||||
journalctl -u officer-pty-sidecar
|
|
||||||
|
|
||||||
# Fix: Install system Node
|
# Or manually install:
|
||||||
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
||||||
sudo apt-get install -y nodejs
|
sudo apt-get install -y nodejs
|
||||||
|
|
||||||
# Restart service
|
# Verify
|
||||||
sudo systemctl restart officer-pty-sidecar
|
node --version # Should be v22.x.x
|
||||||
```
|
```
|
||||||
|
|
||||||
### "pi: command not found"
|
### "pi: command not found"
|
||||||
@@ -271,12 +263,17 @@ sudo systemctl restart officer-pty-sidecar
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Next Steps
|
## Quick Start
|
||||||
|
|
||||||
1. Install Node.js: `curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt-get install -y nodejs`
|
```bash
|
||||||
2. Run setup: `bash scripts/setup.sh`
|
cd /path/to/officer/monorepo
|
||||||
3. Start Officer: `bun dev` (or PM2/systemd in production)
|
bash scripts/setup.sh
|
||||||
4. Open browser: `http://localhost:5000` (or your configured port)
|
bun dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open browser: `http://localhost:5000` (or your configured port)
|
||||||
|
|
||||||
|
That's it! Everything is installed automatically.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+22
-7
@@ -268,9 +268,10 @@ if has node; then
|
|||||||
if [ "$NODE_MAJOR" = "22" ]; then
|
if [ "$NODE_MAJOR" = "22" ]; then
|
||||||
skip "node v$NODE_VER (system-wide)"
|
skip "node v$NODE_VER (system-wide)"
|
||||||
else
|
else
|
||||||
warn "Node $NODE_VER found but v22 is required — upgrading via NodeSource..."
|
warn "Node $NODE_VER found but v22 is required — upgrading..."
|
||||||
case $PM in
|
case $PM in
|
||||||
apt)
|
apt)
|
||||||
|
echo " Setting up NodeSource repository..."
|
||||||
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
||||||
sudo apt-get install -y nodejs
|
sudo apt-get install -y nodejs
|
||||||
if has node && [ "$(node -v | cut -d. -f1 | tr -d 'v')" = "22" ]; then
|
if has node && [ "$(node -v | cut -d. -f1 | tr -d 'v')" = "22" ]; then
|
||||||
@@ -279,26 +280,40 @@ if has node; then
|
|||||||
fail "Node.js upgrade failed"
|
fail "Node.js upgrade failed"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
pacman)
|
||||||
warn "Manual upgrade needed for $PM: install Node.js 22 from official sources"
|
install_pkg nodejs npm
|
||||||
|
if has node; then ok "node v$(node -v) installed"; else fail "node install failed"; fi
|
||||||
|
;;
|
||||||
|
brew)
|
||||||
|
install_pkg node
|
||||||
|
if has node; then ok "node v$(node -v) installed"; else fail "node install failed"; fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
warn "Node.js not found — installing v22 via NodeSource..."
|
echo " Node.js not found — installing v22..."
|
||||||
case $PM in
|
case $PM in
|
||||||
apt)
|
apt)
|
||||||
|
echo " Setting up NodeSource repository (this may take a moment)..."
|
||||||
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
||||||
|
echo " Installing nodejs from apt..."
|
||||||
sudo apt-get install -y nodejs
|
sudo apt-get install -y nodejs
|
||||||
if has node; then ok "node v$(node -v) installed"; else fail "node install failed"; fi
|
if has node; then
|
||||||
|
ok "node v$(node -v) installed from NodeSource"
|
||||||
|
else
|
||||||
|
fail "Node.js install failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
pacman)
|
pacman)
|
||||||
|
echo " Installing nodejs from pacman..."
|
||||||
install_pkg nodejs npm
|
install_pkg nodejs npm
|
||||||
if has node; then ok "node v$(node -v) installed"; else fail "node install failed"; fi
|
if has node; then ok "node v$(node -v) installed"; else fail "node install failed"; exit 1; fi
|
||||||
;;
|
;;
|
||||||
brew)
|
brew)
|
||||||
|
echo " Installing node from brew..."
|
||||||
install_pkg node
|
install_pkg node
|
||||||
if has node; then ok "node v$(node -v) installed"; else fail "node install failed"; fi
|
if has node; then ok "node v$(node -v) installed"; else fail "node install failed"; exit 1; fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user