{"record":{"id":"1573d94b933195df","repo":"denoland/deno","slug":"deno-kernel-already-exists-at-run-again-with","errorCode":null,"errorMessage":"Deno kernel already exists at {}, run again with `--force` to overwrite it","messagePattern":"Deno kernel already exists at (.+?), run again with `--force` to overwrite it","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tools/jupyter/install.rs","lineNumber":152,"sourceCode":"  maybe_name: Option<&str>,\n  maybe_display_name: Option<&str>,\n  force: bool,\n) -> Result<(), AnyError> {\n  let user_data_dir = get_user_data_dir()?;\n\n  let kernel_name = maybe_name.unwrap_or(\"deno\");\n  let kernel_spec_dir_path = user_data_dir.join(\"kernels\").join(kernel_name);\n  let kernel_spec_path = kernel_spec_dir_path.join(\"kernel.json\");\n\n  std::fs::create_dir_all(&kernel_spec_dir_path).with_context(|| {\n    format!(\n      \"Failed to create kernel directory at {}\",\n      kernel_spec_dir_path.display()\n    )\n  })?;\n\n  if kernel_spec_path.exists() && !force {\n    bail!(\n      \"Deno kernel already exists at {}, run again with `--force` to overwrite it\",\n      kernel_spec_dir_path.display()\n    );\n  }\n\n  let display_name = maybe_display_name.unwrap_or(\"Deno\");\n  let current_exe_path = kernel_exe_path()?.to_string_lossy().into_owned();\n\n  // TODO(bartlomieju): add remaining fields as per\n  // https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs\n  let json_data = json!({\n      \"argv\": [current_exe_path, \"jupyter\", \"--kernel\", \"--conn\", \"{connection_file}\"],\n      \"display_name\": display_name,\n      \"language\": \"typescript\",\n  });\n\n  let f = std::fs::File::create(&kernel_spec_path).with_context(|| {\n    format!(","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/jupyter/install.rs#L134-L170","documentation":"`deno jupyter --install` writes a kernel spec to <user-data-dir>/kernels/<name>/kernel.json. By default it will not overwrite an existing kernel spec (named 'deno' unless --name was given); if kernel.json already exists and --force was not passed, installation aborts with this error.","triggerScenarios":"Running `deno jupyter --install` a second time; switching Deno versions and reinstalling the kernel; a custom --name colliding with an existing kernel entry.","commonSituations":"Re-running setup scripts/Dockerfiles that install the kernel on every build; multiple Deno installations sharing one Jupyter user dir.","solutions":["Re-run with `deno jupyter --install --force` to overwrite the existing spec","Or remove the old kernel dir first: delete <user-data-dir>/kernels/<name>/ (e.g. ~/.local/share/jupyter/kernels/deno/)","Or install under a different name with `--name <other>` to keep both"],"exampleFix":"# before\ndeno jupyter --install   # Deno kernel already exists at ...\n\n# after\ndeno jupyter --install --force\n# or\nrm -r ~/.local/share/jupyter/kernels/deno && deno jupyter --install","handlingStrategy":"validation","validationCode":"# make kernel install idempotent in setup scripts:\ndeno jupyter --install --force   # overwrites safely instead of failing","typeGuard":null,"tryCatchPattern":"Catch 'Deno kernel already exists'; decide policy — re-run with --force (overwrite) or skip if the existing spec already points at the current deno binary.","preventionTips":["Use `--force` in Dockerfiles and setup scripts that re-run","Reinstall the kernel after `deno upgrade` so kernel.json points at the current binary","Use `--name` to keep multiple kernels side by side"],"tags":["jupyter","kernel","install","idempotency","overwrite-protection"],"backgroundTag":"resource-already-exists","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}